djanim8 Posted August 23, 2006 Share Posted August 23, 2006 I want to get all records from a mySQL database that have a date for this week (starting on Sunday)..I can get the day of the week (today is Wed...) by doing this: date("w");so how can I subtract this many days (3) from today's date to get the start? and then add 6 to that date to get the end.. for example:this is todays date: 08/23/2006I want to make a dymanic sql statement like this for THIS week (and then whatever week after that).$mySQL = "SELECT * FROM thistable WHERE thisdate IS BETWEEN ".$firstDate." AND ".$lastDate;Where first date would be this sunday (08/20/2006) and the last date would be this saturday (08/26/2006)I can't seem to find code to add and subtract from the current date :( Quote Link to comment Share on other sites More sharing options...
Barand Posted August 23, 2006 Share Posted August 23, 2006 try[code]<?php$d = "08/23/2006";$t = strtotime($d);$dow = date('w', $t);$d1 = strtotime ("-$dow days", $t);$d2 = strtotime ("+6 days", $d1);$firstdate = date ('Y-m-d', $d1);$lastdate = date ('Y-m-d', $d2);echo $firstdate, ' ', $lastdate;?>[/code] Quote Link to comment 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.