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 |
|
kieran5405
Yak Posting Veteran
96 Posts |
Posted - 2008-08-27 : 13:30:05
|
| Hi,I have an nVarchar column where users enter in specific times i.e. 10:45am, 2:45pm, 8:00am, 9:00pmWhat is my best option to order these by time. I was looking at the datepart but cant get it working for me as I only have the times entered...no dates.Thanks for any help... |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-27 : 13:35:02
|
| convert it to datetime and then sort |
 |
|
|
kieran5405
Yak Posting Veteran
96 Posts |
Posted - 2008-08-28 : 05:00:13
|
Hi,Thanks for reply...If I do this, then the result I get is = 19-01-13 07:12:00:000select convert(datetime, 12.30)Obviously the date doesnt matter...its only the time...but the time appears to be showing as 07:12 which wont work.I can have the time in the format 12.30 or 12:30...Any ideas...quote: Originally posted by visakh16 convert it to datetime and then sort
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-28 : 05:07:37
|
| CONVERT(datetime,'12:30') |
 |
|
|
kieran5405
Yak Posting Veteran
96 Posts |
Posted - 2008-08-28 : 05:28:24
|
of course!!! sorry about that!!! cheers...quote: Originally posted by visakh16 CONVERT(datetime,'12:30')
|
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2008-08-28 : 05:37:43
|
quote: Originally posted by kieran5405 If I do this, then the result I get is = 19-01-13 07:12:00:000select convert(datetime, 12.30)
That's because you are converting date 12.30 to datetimeconvert(datetime, 0) date 0 is 1900-01-01 convert(datetime, 12.30) 12 days after 0 is 1900-01-13 0.30 of 1 day => 0.3 x 24 hours = 7.2 Hours 7.2 Hours => 7 hour 12 minswhich gives you 1900-01-13 07:12Specify the time in string as what visakh as shown KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|
|
|
|