note 1881 deleted from function.mktime by vincent
| From: | vincent@php.net | Date: | Wed, 10 Sep 2003 19:08:57 +0000 |
| Subject: | note 1881 deleted from function.mktime by vincent | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-56011@lists.php.net to get a copy of this message | ||
Note Submitter: scott-at-maxify.com
----
It's typically easier to keep all the data in numeric form, rather than attempting to parse the
data later, than convert it into numbers, and ultimately feed it to mktime().
For example, to get a date from user-submitted data, then convert it to epoch time, first create an
HTML form that looks something like this:
<pre>
<select name="month" size="1">
<option value="1" selected>January
<option value="2">February
<option value="3">March
[* edited for length *]
<option value="10">October
<option value="11">November
<option value="12">December
</select>
<select name="day" size="1">
<option value="1" selected>1
<option value="2">2
<option value="3">3
<option value="4">4
[* edited for length *]
<option value="29">29
<option value="30">30
<option value="31">31
</select>
<select name="year" size="1">
<option value="1999">1999
<option value="2000">2000
<option value="2001">2001
<option value="2002">2002
</select>
</pre>
Verify the date is valid (not February 31, for example):
<pre>
if (!checkdate($month,$day,$year)) {
die ("Not that many days in that month.");
}
</pre>
Finally, convert to epoch time:
<pre>
$someDate = mktime(0,0,0,$month,$day,$year);
</pre>