Re: Last Sunday in September?
| From: | Joel Leibow | Date: | Fri, 17 Feb 2006 23:21:04 +0000 |
| Subject: | Re: Last Sunday in September? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-230671@lists.php.net to get a copy of this message | ||
Here is how I did it.
<?php
//total days in september
$septNumberOfDays = 30;
//get the day of the month for 12:00:00am on the last day of September of
the current year
$septLastDay = date('w', mktime(0, 0, 0, 9, $septNumberOfDays, date('Y')));
//if the last day itself isn't a sunday
if($septLastDay != 0) {
//set the last sunday timestamp
$septLastSunday = mktime(0, 0, 0, 9, ($septNumberOfDays - $septLastDay),
date('Y'));
} else {
//otherwise set the last sunday timestamp to the last day of sept
$septLastSunday = mktime(0, 0, 0, 9, $septNumberOfDays, date('Y'));
}
print date('l, F j, Y', $septLastSunday);
?>
"Jay Paulson" <Jay.Paulson@wholefoods.com> wrote in message
news:C01B6D00.16EB%Jay.Paulson@wholefoods.com...
> Hi,
>
> I'm building a program and I need to find the last Sunday in September for
> every year because the following Monday is the start of a new year for us.
> So 2006 ends on September 24th 2006 and the new year (2007) starts on
> September 25th 2006. I was thinking that using the strtotime() would get
> me
> this information possibly? Is there an easy way to get this information?
>
> Pseudo code:
>
> If ((date > last Sunday in September this year) &&
> (date < Jan 1 of next year)) {
> year++
> }