datetime datatype question.

  • 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

  • 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.

  • 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')

  • 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

  • I guess more people do the convert than I thought......may not be the best way, but looks like its the accepted way.....

  • 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.

  • 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