how to search specific datetime in sql server 2005
-
hi. I'm trying to locate the date/time of a certain data. I've tried the typical "SELECT * FROM this_table WHERE column_name = ''. This does not return anything. Can someone help me with this? I want to search quickly for the specified date and time. Thanks!
-
hi. I'm trying to locate the date/time of a certain data. I've tried the typical "SELECT * FROM this_table WHERE column_name = ''. This does not return anything. Can someone help me with this? I want to search quickly for the specified date and time. Thanks!
Hi, If the data type of column_name is datetime, 'some date' should be convertible to datetime implicitely or you should convert it explicitely. For conversion use CONVERT function. For example:
column_name = CONVERT(datetime, '2008-09-07 12:02:00', 120)
Also notice that this is exact match so minutes, seconds and so on must match. Mika
-
Hi, If the data type of column_name is datetime, 'some date' should be convertible to datetime implicitely or you should convert it explicitely. For conversion use CONVERT function. For example:
column_name = CONVERT(datetime, '2008-09-07 12:02:00', 120)
Also notice that this is exact match so minutes, seconds and so on must match. Mika
-
If you know for sure that the time is always at midnight, then you can use equality like:
column_name = CONVERT(datetime, '2008-09-07', 105)
If time portion can vary, use ranges like:
... column_name >= CONVERT(datetime, '2008-09-07', 105)
AND column_name < CONVERT(datetime, '2008-09-08', 105)Hope this helps, Mika