SQL Get Date

Results 1 to 3 of 3

Thread: SQL Get Date

  1. #1
    Join Date
    Dec 1969

    Default SQL Get Date

    How can i retrieve a date from sql database without time?<BR>I want to retrieve all records from database that have the todays date.<BR>if i say: <BR>select * from table <BR>where date=getdate()<BR><BR>i do not get any records because the comparison is done base on time.<BR>

  2. #2
    Join Date
    Dec 1969

    Default one way.....

    &nbsp;<BR>select * from table <BR>where date=(cast(datepart(day, getDate()) as varchar) + &#039;/&#039; + cast(datepart(month, getDate()) as varchar) + &#039;/&#039; + cast(datepart(year, getDate()) as varchar))<BR><BR>is one way of doing it, but there is probably a better way, this should work though!<BR>

  3. #3
    Join Date
    Dec 1969

    Default another way

    SELECT * FROM Table WHERE CONVERT(varchar(10),TheDateField,105) = CONVERT(VARCHAR(10),GetDate(),105)<BR><BR>(check BOL for the CONVERT function to see why this works)<BR><BR>and there are more ways to do this... e.g. with the DATEDIFF function.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts