Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.