Help requested on getdate

  • Hi-

      I am trying to figure out how to obtain data for a particular day without having to re-type the new day everyday.  Basically I am looking at a backorder file that appends new data daily and has a field called "Backorder_date", which would be equal to today's date if the item went into backorder.  In my query I have a select where backorder_date=getdate()  but that will not work because the getdate() will not be equal to the backorder_date because of the time. 

    Is there a way to ignore the time and just look at the actual date?

     

    Thanks for your help!

  • Try this:

     

    select

    convert(smalldatetime,convert(varchar(10),getdate(),101))

     

  • Or try this:

    select dateadd(dd,datediff(dd,getdate()),0)

  • I think you have a typo.  This will do what you want.

    select dateadd(dd,datediff(dd,0,getdate()),0)
  • That code would produce an error if the dateformat in non-US, for example dmy is normal in UK.

     

     

  • The first code worked perfect.  Thank you very much for your assistance!

  • even if it works for you, you should still use this method

    select dateadd(day, datediff(day, 0, getdate()), 0)

    as it is not depend on your date format or language settings. It will work anywhere. And it is definitely faster than the double convert method.

  • Thanks!  I'll use this one. 

  • Michael, Regarding the typo, that's what I get for writing the select statement on one system and typing it on another (didn't use cut and paste).

    Thanks

  • Well ... it gives error on my SQL Server

    select dateadd(dd,datediff(dd,getdate()),0)

    Server: Msg 174, Level 15, State 1, Line 1

    The datediff function requires 3 arguments.

  • KH, That's because of the typo.  I left out the '0,' after the 'dateadd(dd,', which is what Michael was tell me.

Viewing 11 posts - 1 through 10 (of 10 total)

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