GETDATE function conversion

  • Hi,

    Would anyone know how to convert the getdate funtion on the fly. I have a table where I am trying to do the following:

    SELECT RETUDATE

    FROM SVC05000

    WHERE (RETUDATE = GETDATE())

    GETDATE field does not exist in the database. I am trying to select any RETUDATE that matches with current system date.

    It's returning null because GETDATE is displaying the current system time as well. I only want to extract the date in (yyyy/mm/dd) format. Maybe I am not aware of another funtion if there is.

    Any help is appreciated...

    Thank you.

  • Try this:

    SELECT RETUDATE

    FROM SVC05000

    WHERE RETUDATE = (SELECT CONVERT(varchar(15),getdate(),111))

    Be great!

    Michael


    Be great!
    Michael

  • Hi,

    You could use the Convert function to convert the date into the format required...

    Convert(Varchar(10),getdate(),111) will convert the date into the yyyy/mm/dd format and you can then use :

    SELECT RETUDATE FROM SVC05000 WHERE

    RETUDATE = CONVERT(Varchar(10),getdate(),111)

    further info on Convert can be found in BOL

  • Try

    Where datediff(d,RETUDATE,getdate()) = 0

  • I know it's nitpicky, but:

    
    
    Where RETUDATE = datediff(d,0,getdate())

    is a little more optimizer-friendly since the field is isolated on the left side of the expression. The query optimizer can reduce DATEDIFF(day, 0, GETDATE()) to a constant, whereas DATEDIFF(day, RETUDATE, GETDATE()) adds an extra evaluation effort to the query. This all assumes, of course, that RETUDATE has already been stripped of any time component...

  • If you're just trying to get the current day's records from a date/time field, this seems to work well:

    select * from SVC05000

    where left(RETUDATE, 10) = left(getdate(), 10)

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply