Re: Date Question
| From: | Matthew Leingang | Date: | Tue, 15 Aug 2000 11:14:49 +0000 |
| Subject: | Re: Date Question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11786@lists.php.net to get a copy of this message | ||
Brian,
Here's an algorithm: You can do it all with mktime() and getdate().
Take the day of the month, add the numerical day of the week of the first
day of that month, as in
$date = getdate($timestamp);
$first = mktime(0,0,0,$date["month"],1,$date["year"]);
$first_dow = $first["wday"];
Then I think you need to add 1 to correct for the fact that Sunday is day
0 of the week. Divide by 7, discarding remainders. Now add 1 AGAIN
because otherwise you have a 0th week of the month.
I think that works, but I haven't tested it. The thing you may not want
is that a week that ends in, say, Saturday April 1 is still called the
first week of April. As well as the 5th week of March.
Anyway, good luck.
--Matt
----------------------------------------------------------------
Matthew Leingang 617/495-2171
Harvard University leingang@math.harvard.edu
Department of Mathematics "This signature needs no quote."
On Mon, 14 Aug 2000, Brian B. wrote:
>
> I was wondering if someone would know how I could take a date and tell
> what week it was of the month? For instance If it was the first week
> of May, 2nd week of May, 3rd week of May or 4th week, and be able to do
> this for all months? Is there some code out there?
>
> Any help would be greatly appreciated.
>
> brian