note 26646 deleted from function.mktime by sniper
| From: | sniper@php.net | Date: | Tue, 04 Nov 2003 13:11:26 +0000 |
| Subject: | note 26646 deleted from function.mktime by sniper | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-59880@lists.php.net to get a copy of this message | ||
Note Submitter: jjones at quakejunkie dot net
----
i realize this function is similar to some posted, but i needed to get the first day of any given
week (my script needs to output "the week of %B %d", i.e. for today, 7-Nov, it should say
"the week of November 3"), and it took me a while to adapt other functions posted here to
the task -- so i figured i'd share it:
// weekof() takes a timestamp as an optional argument
function weekof($wo_time = NULL) {
// making $wo_time default to NULL and doing isset was the only way
// i could get it to not spit out warnings if no argument was passed
if(!isset($wo_time)) { $wo_time = time(); }
// change the output format here if you'd like
$wo_format = "%m-%d-%Y";
$wo_month = strftime("%m",$wo_time);
$wo_day = strftime("%d",$wo_time);
$wo_year = strftime("%Y",$wo_time);
$wo_day -= strftime("%w",$wo_time);
// the line that works the magic ;]
return strftime($wo_format,mktime(0, 0, 0, $wo_month, $wo_day, $wo_year));
}