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:
-
$lastSunday =
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)));
-
$nextSaturday =
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)));
Question, Comments...
Do you have more questions. Please either leave a comment below or join us in our new forum.
Tags: Coding, php, tips
This entry was posted
on Sunday, February 1st, 2009 at 7:56 am and is filed under Coding, Tips & Tricks.
You can follow any responses to this entry through the RSS 2.0 feed.
You can leave a response, or trackback from your own site.