note 55229 added to function.strtotime

From: Date: Thu, 28 Jul 2005 02:33:58 +0000
Subject: note 55229 added to function.strtotime
Groups: php.notes 
Request: Send a blank email to php-notes+get-92606@lists.php.net to get a copy of this message
I needed a drop down box so users could see their account balance for the given time period. Below is a drop box that displays the first of the month for the last twelve months and the value of each is the timestamp of that date. <? $time = time(); $month = date("F"); $year = date("Y"); $string = "1 "; $string .= $month; $string .= " "; $string .= $year; $first_timestamp = strtotime($string); $start_box = "<select name='start_date' size='1'><option>Start Date</option>"; $end_box = "<select name='end_date' size='1'><option>End Date</option>"; for ($i = 0; $i <= 12; $i++) { $temp = "-"; $temp .= $i; $temp .= " month"; $timestamp_first = strtotime($temp, $first_timestamp); $formatted_first = date("F j, Y", $timestamp_first); $box .= "\n<option value='"; $box .= $timestamp_first; $box .= "'>"; $box .= $formatted_first; $box .= "</option>\n"; } $start_box .= $box; $end_box .= $box; $start_box .= "</select>"; $end_box .= "</select>"; ?> Once submitted it was very easy to pull from the db what you needed between the two timestamps. I'm sure it could be condensed a bit, but the logic is there. Hope this helps someone. GG ---- Manual Page -- http://www.php.net/manual/en/function.strtotime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+55229 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+55229&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+55229&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+55229&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+55229&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+55229&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+55229&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+55229&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#92606) next »