Re: date functions

From: Date: Sat, 16 Dec 2000 21:09:02 +0000
Subject: Re: date functions
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-30678@lists.php.net to get a copy of this message
When the date see a non-existent date, it loops to the next month/day, so November 31 would return December 1, so you could do something like this. for($month = 1;$month <= 12;$month++) {
        $monthname = date("F",mktime(0,0,0,$month,1,2000));
        for($day = 1;$day <= 31;$day++) {
                $datetime = mktime(0,0,0,$month,$day,2000);
                if($monthname == date("F",$datetime)) {
                        echo date("F d Y",$datetime) . "<br>";
                        //or anything else you want to do
                };
        };
}; This would return a list of all the days of the year, in the form: January 01 2000 January 02 2000 ... December 30 2000 December 31 2000 skipping all non-existant days, such as February 30, 2000. Matthew At 03:30 PM 12/16/2000 +0100, you wrote:
Yo! I'm currently working in a calendar and I've run into problems. I use this code to create a <select> tag with 12 <option> tags, one for each month. $month = 1; while ($month <= 12) { echo "<option value=" . date("F", mktime(0, 0, 0, $month, 1, 2000)).">".date("F", mktime(0, 0, 0, $month, 1, 2000)); ++$month; } this works fine, but now I want to list all the days in a certain month, and I don't know how to achieve that. I can't use a while statement as with the months, because I don't know how many days it will be in a certain month, (I know that it will allways be 12 months though) so how can I do this? Any help much appreciated!! /Broder


« previous php.general (#30678) next »