Help to query a date range

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • matthewanxa
    New Member
    • Jul 2008
    • 2

    Help to query a date range

    Please forgive me, I am a neophyte at this :)

    I need to select all records created today

    I can't use GetDate because it looks for a specific hour minute and second so I need a range.

    ie select records created less than or equal to current date except less than 1 day ago.

    I will run this query at exactly the same time everyday so that will not vary.

    I can select the records of today but am not successfully excluding records of the previous day.

    thank you for your advise on this.

    is there a hours before function instead of days before??
  • ck9663
    Recognized Expert Specialist
    • Jun 2007
    • 2878

    #2
    try:

    Code:
    select * from yourtable where datediff(dd,yourdatefield,getdate()) = 0
    remember that getdate() returns system date. if you ran this at 12MN, you might forgot it's already the following day.

    -- CK

    Comment

    • matthewanxa
      New Member
      • Jul 2008
      • 2

      #3
      Dear ck9663

      Thank you very much for this. It worked perfectly, exactly what I needed.

      I just removed the dd, as it is not needed - I just need the difference between the datediff(dateCr eated,getDate() ) = 0

      for day 3 I am using the same with = -2 and for day 5 the same with = -4

      Just to clarify, I am sending a series of reminder emails (day 1 day 3 and day 5) so I need to identify everyday a new batch and fire off the correct template (3 different templates 1 for each day).

      Thank you very much for you help on this - I am learning fast :))

      Matthew


      Originally posted by ck9663
      try:

      Code:
      select * from yourtable where datediff(dd,yourdatefield,getdate()) = 0
      remember that getdate() returns system date. if you ran this at 12MN, you might forgot it's already the following day.

      -- CK

      Comment

      Working...