Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2007-01-11 : 06:46:29
|
Meera writes "Im using SQL server Enterprise Manager When I query the data I have column called DateTime which is in format ex: 12/6/2006 1:50:09 PMHow can I separate the date and time into two different columns? Such as ‘12/6/2006’ AND ‘1:50:09 PM’" |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-11 : 06:48:28
|
[code]SELECT DATEADD(day, DATEDIFF(day, 0, getdate()), 0) AS theDate, DATEADD(second, DATEDIFF(second, DATEADD(day, DATEDIFF(day, 0, getdate()), 0), getdate()), DATEADD(day, DATEDIFF(day, 0, getdate()), 0)) AS theTime[/code]Peter LarssonHelsingborg, Sweden |
 |
|
swatib
Posting Yak Master
173 Posts |
Posted - 2007-01-12 : 03:42:56
|
To extract only time from the datetime field:select convert(varchar(10), getdate(), 108)To extract only date from the datetime field:select convert(varchar(10), getdate(), 101)Njoy Life |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2007-01-12 : 05:25:01
|
Yes, if you want to change datatype too.Peter LarssonHelsingborg, Sweden |
 |
|
swatib
Posting Yak Master
173 Posts |
Posted - 2007-01-12 : 06:03:21
|
Sure. if you are just displaying such separate date and time in pages or in reports, then it is fine.Njoy Life |
 |
|
|
|
|
|
|