note 56598 added to function.mktime

From: Date: Thu, 08 Sep 2005 16:40:31 +0000
Subject: note 56598 added to function.mktime
Groups: php.notes 
Request: Send a blank email to php-notes+get-94921@lists.php.net to get a copy of this message
I needed a script to display a dropdown menu with a list of week ending dates. I wrote this as a result. I hope it helps somebody. The selname variable is the name of the select field and the day of week of the begining date designates the end of the week. <?php $selname="we_date"; //Build Begin date $month=10; $day=04; $year=2003; $hour=date('H'); $min=date('i'); $sec=date('s'); //convert it to unix timestamp $bdate=mktime($hour,$min,$sec,$month,$day,$year); //Build Today $thour=date('H'); $tmin=date('i'); $tsec=date('s'); $tmonth=date('n'); $tday=date('d'); $tyear=date('Y'); //convert it to unix timestamp $today=mktime($thour,$tmin,$tsec,$tmonth,$tday,$tyear); //just the weeks $nbdate=floor($bdate/(7 * 24 * 60 * 60)); $ntoday=floor($today/(7 * 24 * 60 * 60)); //difference between today and the beginning date $diff=$today-$bdate; echo "<select size='1' name='$selname'>\n"; while ($bdate <= $today+(7 * 24 * 60 * 60)){ echo ("<option value='".date('n/d/Y',$bdate)."'> ".date('n/d/Y',$bdate)."</option>\n"); $bdate=$bdate+(7 * 24 * 60 * 60); } echo "</select>"; ?> ---- Manual Page -- http://www.php.net/manual/en/function.mktime.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+56598 Delete: added to the manual -- http://master.php.net/manage/user-notes.php?action=delete+56598&report=yes&reason=added+to+the+manual Delete: bad code -- http://master.php.net/manage/user-notes.php?action=delete+56598&report=yes&reason=bad+code Delete: spam -- http://master.php.net/manage/user-notes.php?action=delete+56598&report=yes&reason=spam Delete: useless -- http://master.php.net/manage/user-notes.php?action=delete+56598&report=yes&reason=useless Delete: non-english -- http://master.php.net/manage/user-notes.php?action=delete+56598&report=yes&reason=non-english Delete: other reasons -- http://master.php.net/manage/user-notes.php?action=delete+56598&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+56598&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#94921) next »