Re: date list

From: Date: Wed, 02 May 2001 09:27:01 +0000
Subject: Re: date list
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-51107@lists.php.net to get a copy of this message
Jon, Try this ... I know the code could be trimmed down, but I wrote it this way for ease of reading. <select name="Date"> <? $startday = "01"; $startmonth = "01"; $staryear = "01"; $endday = "01"; $endmonth = "07"; $endyear = "01"; $startperiod = mktime(0,0,0,$startmonth,$startday,$startyear); $endperiod = mktime(0,0,0,$endmonth,$endday,$endyear); while($startperiod <= $endperiod) { $date = getdate($startperiod); $year = $date['year']; $month = $date['mon']; $day = $date['mday']; echo "<option value=\"$year-$month-$day\">"; echo "$month/$day/$year"; echo "</option>\n"; $startperiod = $startperiod + 86400; } ?> </select> Basically just uses mktime() and getdate() The 86400 is the number of seconds in the day, and the option value is set to return in the format YYYY-MM-DD (that format's used a lot in MySQL tables). Have fun ;) James. > 01/01/01-01/07/01 > 01/08/01-01/14/01 > 01/15/01-01/21/01 > etc > etc > till the end of 2002 and further in the future eventually > > I'd like to make PHP generate this for me so I don't have to handcode it for > each year in the future. I've looked at the date/time functions and I'm a > bit confused. Any help would be appreciated. Thanks! > > Jon > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net > For additional commands, e-mail: php-general-help@lists.php.net > To contact the list administrators, e-mail: php-list-admin@lists.php.net >

« previous php.general (#51107) next »