Jump to content

[SOLVED] Date Ranges?


random1

Recommended Posts

Hi All,

 

Im pretty new to MySQL. My web app currently has a table of users and my interface has a date range picker: 1st is now <- 30days, 2nd is now -> 30days (two select lists).

 

How in mysql can you do date range filtering?

 

e.g.

 

SELECT `user_name` FROM `user`
WHERE `user_registration_datetime` > NOW() - 1 week
AND `user_registration_datetime` < NOW() + 1 week

 

(I'd like to select the info for `user` where the user registration datetime is 1 week back or 1 week forward)

Link to comment
https://forums.phpfreaks.com/topic/135434-solved-date-ranges/
Share on other sites

Thanks,

 

I ended up with:

 

SELECT UTC_TIMESTAMP() + INTERVAL 1 MONTH AS `now + 1 month`;

SELECT UTC_TIMESTAMP() - INTERVAL 1 MONTH AS `now - 1 month`;

 

and

 

SELECT * FROM `user`
WHERE `user_datetimelastlogin`
BETWEEN UTC_TIMESTAMP() - INTERVAL 1 MONTH 
AND UTC_TIMESTAMP();

 

People that don't use UTC timestamps need to replace UTC_TIMESTAMP() with NOW().

Link to comment
https://forums.phpfreaks.com/topic/135434-solved-date-ranges/#findComment-705550
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.