RE: [PHP] date, "first of next month"?
| From: | Jon Haworth | Date: | Thu, 27 Feb 2003 09:42:33 +0000 |
| Subject: | RE: [PHP] date, "first of next month"? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-137369@lists.php.net to get a copy of this message | ||
Hi Bryan,
> > $t = mktime(0,0,0,date('m')+1,1,date('Y'));
> >
> > Gives you timestamp of first day, next month.
> > Format accordingly with date().
>
> is there such a say to now get the date of the first
> weekday after that date?
You can brute force it:
// grab the timestamp
$t = mktime(0,0,0,date('m')+1,1,date('Y'));
// if it's a saturday or sunday, add 86400 seconds (1 day)
while (date('w',$t) == 0 || date('w',$t) == 6)
$t += 86400;
This doesn't take into account any bank holidays, of course - you'll need to
do a lookup against a database or an array if you want to test for these as
well (not sure if you want the first weekday or the first working day).
There might be a more elegant way to do this, but with a maximum of three
iterations round the while loop, I don't know if it's worth looking for :-)
HTH
Jon