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 :( Link to comment https://forums.phpfreaks.com/topic/18471-getting-info-from-a-database-by-week/ 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] Link to comment https://forums.phpfreaks.com/topic/18471-getting-info-from-a-database-by-week/#findComment-79497 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.