PHP functions for next Saturday and previous Sunday

I needed a way to find the first second of a week and the last second of a week based on a Unix timestamp.

Credit for the previous Sunday goes to Shaun who posted a way to find it on the PHP site for strftime, although I changed his code a little because I’m more comfortable with the date() function.

$last_sunday = mktime(0, 0, 0, date('m', $start_date), date('d', $start_date), date('Y', $start_date)) - ((date("w", $start_date) ==0) ? 0 : (86400 * date("w", $start_date)));
$next_saturday = mktime(23, 59, 59, date('m', $end_date), date('d', $end_date), date('Y', $end_date)) + ((date('w', $end_date)==6) ? 0 : 86400 * (6 - date('w', $end_date))); 
This entry was posted in Programming. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>