otuatail Posted May 27, 2010 Share Posted May 27, 2010 Hi this is a dificult one for me. I want to select records from the last 3 days. ie select * from table where Date > '2010-05-24 00:00:00' and Date < '2010-05-27 23:59:59' I can get todays date and add 23:59:59. The problem is subtracting three days. is there any mysql function that can be used for the first date (today - 3 days) Desmond. Quote Link to comment https://forums.phpfreaks.com/topic/203086-select-records-within-a-date-range/ Share on other sites More sharing options...
otuatail Posted May 27, 2010 Author Share Posted May 27, 2010 Ok I think I have nearly solved this. This works SELECT * FROM WorldCup WHERE Date > DATE_ADD( CURDATE( ) , INTERVAL 15 DAY ) AND Date < DATE_ADD( CURDATE( ) , INTERVAL 16 DAY ) This dosn't SELECT * FROM WorldCup WHERE Date > DATE_ADD( CURDATE( ) +'00:00:00', INTERVAL 15 DAY ) AND Date < DATE_ADD( CURDATE( ) + '23:59:59', INTERVAL 15 DAY ) How do I get the hours into it as it will default to midnight. Quote Link to comment https://forums.phpfreaks.com/topic/203086-select-records-within-a-date-range/#findComment-1064132 Share on other sites More sharing options...
Maeltar Posted May 31, 2010 Share Posted May 31, 2010 You could try .. DAY(CURDATE()-3) also works with WEEK(CURDATE()-3) MONTH(CURDATE()-3) YEAR(CURDATE()-3) Obviously change the "-3" to suit Quote Link to comment https://forums.phpfreaks.com/topic/203086-select-records-within-a-date-range/#findComment-1065628 Share on other sites More sharing options...
ignace Posted May 31, 2010 Share Posted May 31, 2010 WHERE Date BETWEEN '2010-05-24' AND '2010-05-27' Quote Link to comment https://forums.phpfreaks.com/topic/203086-select-records-within-a-date-range/#findComment-1065798 Share on other sites More sharing options...
fenway Posted June 2, 2010 Share Posted June 2, 2010 You could try .. DAY(CURDATE()-3) also works with WEEK(CURDATE()-3) MONTH(CURDATE()-3) YEAR(CURDATE()-3) Obviously change the "-3" to suit And this won't work anyway -- you need INTERVAL for math. Quote Link to comment https://forums.phpfreaks.com/topic/203086-select-records-within-a-date-range/#findComment-1066862 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.