Pulling records based on timestamp

  • I need to select records that have been created today starting at 12:01a and up to and including when the job runs, but the select is part of a job that can be kicked off at any time. Where can I find a resource that explains how SQL interprets time values in this getdate/interval statement? My search didn't turn up anything that jumped out at me. The syntax below didn't "work" when it ran at 6a and pulled records created the previous day. I know the -1 is too large a value in this case but I can't figure out how to code this so it dynamically pulls from 12:01a to the current time.

    createdatetime BETWEEN (Select getdate() -.1 Interval) AND (Select getdate() -0 Interval)

  • Ron

    Look up the DATEADD, DATEDIFF and DATEPART functions.

    John

  • Use this to start at 00:00:01

    where createdatetime between dateadd(dd,datediff(dd,0,getdate()),'00:01:00.000') and getdate()
  • Thank you both!

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

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