note 84123 added to function.date

From: Date: Mon, 30 Jun 2008 02:18:41 +0000
Subject: note 84123 added to function.date
Groups: php.notes 
Request: Send a blank email to php-notes+get-140992@lists.php.net to get a copy of this message
I wrote the following function to show a series of drop down boxes to select the date. When provided with a timestamp, that date is selected by default, when none is provided, the current date is selected. function chooseDate($timestamp = ""){ if($timestamp == ""){ $timestamp = time(); } $months = array(null, 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'); unset($months[0]); print_r($months); $out = '<select name="month">'; foreach($months as $key => $month){ if($month == date('M', $timestamp)){ $out .= '<option value="'.$key.'" selected="selected">'.$month.'</option>'; }else{ $out .= '<option value="'.$key.'">'.$month.'</option>'; } } $out .= '</select><select name="days">'; for($i = 1; $i <= 32; $i++){ if($i == date('j', $timestamp)){ $out .= '<option value="'.$i.'" selected="selected">'.$i.'</option>'; }else{ $out .= '<option value="'.$i.'">'.$i.'</option>'; } } $out .= "</select><select name='year'>"; for($i = date('Y'); $i >= 1970; $i--){ if($i == date('Y', $timestamp)){ $out .= '<option value="'.$i.'" selected="selected">'.$i.'</option>'; }else{ $out .= '<option value="'.$i.'">'.$i.'</option>'; } } $out .= "</select>"; return $out; } Usage is simple: echo chooseDate(); // Will select current date echo chooseDate(1149566400); // Will select June 6th, 2006 ---- Server IP: 208.69.120.35 Probable Submitter: 98.217.82.231 ---- Manual Page -- http://www.php.net/manual/en/function.date.php Edit -- https://master.php.net/note/edit/84123 Del: integrated -- https://master.php.net/note/delete/84123/integrated Del: useless -- https://master.php.net/note/delete/84123/useless Del: bad code -- https://master.php.net/note/delete/84123/bad+code Del: spam -- https://master.php.net/note/delete/84123/spam Del: non-english -- https://master.php.net/note/delete/84123/non-english Del: in docs -- https://master.php.net/note/delete/84123/in+docs Del: other reasons-- https://master.php.net/note/delete/84123 Reject -- https://master.php.net/note/reject/84123 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140992) next »