fxr Posted February 6, 2009 Share Posted February 6, 2009 is anyone capable of writing me a mysql select statement to select all records since 'last sunday' i.e this week, if my records have a field $datetime as type DATETIME? is mysql even capable of doing this, i had a look at INTERVAL and CURTIME and stuff like that, but its just not going in. can anyone bail me out please? Quote Link to comment https://forums.phpfreaks.com/topic/144012-solved-mysql-select-statement-for-this-week-or-since-sunday/ Share on other sites More sharing options...
corbin Posted February 6, 2009 Share Posted February 6, 2009 Best I can think of is: SELECT * FROM table WHERE column1 > SUBDATE(NOW(), INTERVAL 8 DAYS) AND DAYOFWEEK(column1) >= 1; Quote Link to comment https://forums.phpfreaks.com/topic/144012-solved-mysql-select-statement-for-this-week-or-since-sunday/#findComment-755663 Share on other sites More sharing options...
fenway Posted February 6, 2009 Share Posted February 6, 2009 Since you know the current DAYOFWEEK() and the DAYOFWEEK() value for sunday, it's pretty easy use modulus to substract the correct number of days. Quote Link to comment https://forums.phpfreaks.com/topic/144012-solved-mysql-select-statement-for-this-week-or-since-sunday/#findComment-755813 Share on other sites More sharing options...
fxr Posted February 6, 2009 Author Share Posted February 6, 2009 Best I can think of is: SELECT * FROM table WHERE column1 > SUBDATE(NOW(), INTERVAL 8 DAYS) AND DAYOFWEEK(column1) >= 1; yep.. that seems to have done it . thanks! just it should be SELECT * FROM table WHERE column1 > SUBDATE(NOW(), INTERVAL 8 DAY) AND DAYOFWEEK(column1) >= 1; Quote Link to comment https://forums.phpfreaks.com/topic/144012-solved-mysql-select-statement-for-this-week-or-since-sunday/#findComment-755995 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.