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 |
|
gpiva
Starting Member
47 Posts |
Posted - 2005-02-28 : 01:50:54
|
| I need to compare in a where a datetime field like this: myfield < that current time...anybody can suggest me the easiest way to do it?any help appreciated.Jo |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2005-02-28 : 01:58:46
|
| well, you can use <But you're better off with the DateDiff funtion. Look it up in Books Online.Damian |
 |
|
|
gpiva
Starting Member
47 Posts |
Posted - 2005-02-28 : 02:03:30
|
| Ok I try with datediff but I dont store day month year in the field only the time the thing that I dont like is that using a datetime a storing only day mont year i can use where field < getDate() same scenario using datetime but wiht hr min sec there is not a way like "getTime()" why ? we are force to cast and use datepar or DateDiff ?cheersJo |
 |
|
|
nosepicker
Constraint Violating Yak Guru
366 Posts |
Posted - 2005-02-28 : 17:11:46
|
| If you are storing only time and you want to compare it to a datetime field, you can try something like this:CONVERT(datetime, myfield) < CONVERT(datetime, CONVERT(varchar, ThatCurrentTime, 108))If "myfield" is in a correct time format, then converting it to datetime format will give it a date of 1900-01-01. Converting the other datetime field to a style of 108 then back to datetime will also give it a date of 1900-01-01. Then you can do a normal datetime comparison. |
 |
|
|
|
|
|