Looking for a date function to run in selecting records in a MySQL database. The task is, no matter when the query is run, need it to select records for a specific DAY in the past. In this case, I want it to always select records that were added the previous Saturday. So if I run this query on Monday, it returns records from the previous Saturday....if I run the query on Thursday, it returns records from the previous Saturday, etc. I have it in Oracle, but not quite making the transition to work in MySQL: The "dual" is Oracle specific, so obviously doesn't work in MySQL. So, in a nutshell, is there a "Last Saturday" SQL function I can use for this? TIA for any suggestions.
It seems that if you combined DATEDIFF() and DAYOFWEEK() functions, you could get that functionality. Let me build a quick MySQL table and run a few queries to test this...
Run an If statement If ($to_date){ $query = "SELECT * FROM table WHERE date > '".$from_date."' AND < '".$to_date."'; }else{ $query = "SELECT * FROM table WHERE date = '".$from_date."'"; } $result = mysql_query($query);
select * from <insert table name here> where dayofweek(dateline) = 7 and datediff(dateline, now()) <7 Seemed to work for me... ("dateline" is also my field name, you'll have to substitute yours here too)