Date Comparison Question

  • I have a "start date/time" and "end date/time" and I need to check if a date/time from some table falls between the start and end date/times.  I want to compare everything (both the date and the time).  I've read about the DateDiff function but I can't figure out what to set the 1st parameter ("datepart") to in order to compare the entire date and time.  I've tried using "YYYYMMDDHHMMSS" but it's invalid.  Just using "dd" (as in my example below) doesn't match up enough info to satisfy my requirements.  Can anyone help me out?  Thanks in advance!

    WHERE DateDiff (dd, g.GameStartDateTime, '2004-04-20 00:00:00') >= 0

    AND DateDiff (dd, g.GameStartDateTime, '2004-04-22 00:00:00') <= 0

     

     

  • Why not just

    Where a.Dt >= b.StartDt

    And  a.Dt <= b.EndDt

     

    Sql's Datetime datatype is treated as one.

  • Or use BETWEEN:

    WHERE g.GameStartDateTime BETWEEN a.startdatetime and a.enddatetime

    -SQLBill

Viewing 3 posts - 1 through 2 (of 2 total)

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