Re: easy date question?

From: Date: Wed, 29 May 2002 04:43:48 +0000
Subject: Re: easy date question?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-99628@lists.php.net to get a copy of this message
I came up with a solution that I'd like to share. Could someone confirm whether it's the best approach? Thanks, -Ed --------- source code ---------------- # ex.: GetDay ("Third", "Saturday", 5, 2002); function GetDay($Week, $Day, $Month, $Year) {
        $MonthStartDay = date("w", mktime(0,0,0,$Month,1,$Year) ) + 1;
        switch ($Week)
        {
                case "First" : $Week = 0; break;
                case "Second" : $Week = 7; break;
                case "Third" : $Week = 14; break;
                case "Fourth" : $Week = 21; break;
        }
        switch ($Day)
        {
                case "Sunday" : $Day = 1; break;
                case "Monday" : $Day = 2; break;
                case "Tuesday" : $Day = 3; break;
                case "Wednesday" : $Day = 4; break;
                case "Thursday" : $Day = 5; break;
                case "Friday" : $Day = 6; break;
                case "Saturday" : $Day = 7; break;
        }
        $C = 0;
        if ($MonthStartDay < $Day)
        {
                $C = $Day - $MonthStartDay;
        }
        else if ($MonthStartDay > $Day)
        {
                $C = 7 - $MonthStartDay + $Day;
        }
        return ($C + 1 + $Week);
} -------------------------------- At 05:55 PM 5/28/2002 -0700, Rasmus Lerdorf wrote:
See the PEAR Date/Calc class. On Tue, 28 May 2002, Ed Lazor wrote: How can I find out the date of the 3rd Tuesday of any given month? Thanks, -Ed


« previous php.general (#99628) next »