简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM