November 14, 2002 at 1:31 pm
Question for everyone regarding how Sql Server handles datetime datatypes. Is there an easier way to select everything from a given day other than this? :
SELECT *
FROM tasks
WHERE (runtime > '11/1/2002 12:00') AND (runtime < '11/1/2002 23:59:59')
I would like to be able to do it without putting in the times, too. Is there a function or something I can use to select everything for a given day without worrying about the time?
Thanks!
-Caine
November 14, 2002 at 1:36 pm
I convert my dates to a varchar(12) which drops the timestamp off, then back to a datetime for sorts, order by's, etc....
Don't take this to be the best solution, but it works well, and I'm able to use an = to evaluate a day.
November 14, 2002 at 1:56 pm
Hope this will help
SELECT *
FROM tasks
WHERE (CONVERT(CHAR(10),runtime,101) > '11/1/2002') AND (CONVERT(CHAR(10),runtime,101) < '11/2/2002')
November 14, 2002 at 2:17 pm
Try something like this:
select * from table where convert(char(10),yourdate ,101) = '04/11/2002'
Gregory Larsen, DBA
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
November 14, 2002 at 2:30 pm
I guess more people do the convert than I thought......may not be the best way, but looks like its the accepted way.....
November 14, 2002 at 3:39 pm
I use CONVERT myself, I have seen other soultions which do everything in memory, but in comparision the CONVERT is more percise without need to double check. However, using it does add one read as it gets the format information from I believe the syslanguages table or some other along that line.
November 14, 2002 at 3:40 pm
Thanks for your help everyone. This helps.
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply