PHP find previous Sunday
April 20, 2011 09:28:01 Last update: April 20, 2011 09:28:46
This code fragment shows how to find the previous Sunday using PHP date/time functions.
Sample output:
<?php $current_time = time(); $last_sunday = $current_time - 86400 * date("w", $current_time); $last_sunday_00_00_str = date('m/d/Y 00:00:00', $last_sunday); $last_sunday_00_00_time = strtotime($last_sunday_00_00_str); print "Current time: $current_time\n"; print "Last Sunday same time: $last_sunday\n"; print "Last Sunday 12:00AM: $last_sunday_00_00_str\n"; print "Last Sunday 12:00AM: $last_sunday_00_00_time, " . " formatted: " . strftime("%m/%d/%Y %H:%M:%S", $last_sunday_00_00_time) . "\n"; ?>
Sample output:
Current time: 1303316297 Last Sunday same time: 1303057097 Last Sunday 12:00AM: 04/17/2011 00:00:00 Last Sunday 12:00AM: 1303016400, formatted: 04/17/2011 00:00:00