PHP functions for next Saturday and previous Sunday

Posted in Programming  
E-Mail This Post/Page   

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.

PHP:
  1. $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)));
  2. $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)));

List functions disabled in PHP
GoDaddy and disabled PHP functions
More black & white from Zilker Gardens
RAW, JPG, and the Canon 10d: Part 2
Old software - nDB and nCopy

Leave a Comment