NULL
NULL

Reputation: 1589

sql query date time

i have a datestamp field in my table structure. using sql, i want to find any user who registered in yesterdays date using these time range.

eg: 2010-02-06 14:00:00 2010-02-07 10:00:00

i will be running this query once a day to grab users.

so tomorrow will be: 2010-02-07 14:00:00 2010-02-08 10:00:00

the day after tomorrow will be: 2010-02-08 14:00:00 2010-02-09 10:00:00

etc, etc.

select distinct * from users where loggedTime...

not sure how to query the date range? any ideas thanks

Upvotes: 0

Views: 1143

Answers (1)

Adam Ruth
Adam Ruth

Reputation: 3655

SQL Server

where loggedTime between
   DATEADD(hour, 14, DATEADD(DAY, 0, DATEDIFF(DAY,0,getdate()))) and
   DATEADD(hour, 34, DATEADD(DAY, 0, DATEDIFF(DAY,0,getdate())))

MySQL

where loggedTime between
   curdate() + interval 14 hour and
   curdate() + interval 34 hour

Upvotes: 2

Related Questions