note 32268 deleted from function.strtotime by sniper

From: Date: Tue, 21 Oct 2003 11:02:08 +0000
Subject: note 32268 deleted from function.strtotime by sniper
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-59000@lists.php.net to get a copy of this message
Note Submitter: tippy2k ---- For US date formating (mm-dd-yy[yy]) to Unix Timestamp try this example: <html> <body> <? function stripdash($date) { for($i=1; $i < 10; $i++) { $find = "-0".$i."-"; $replace = "/".$i."/"; $date = str_replace($find, $replace, $date); } for($i=1; $i < 32; $i++) { $find = "-".$i."-"; $replace= "/".$i."/"; $date = str_replace($find, $replace, $date); } return $date; } if ($field) { $date = trim($field); $date = stripdash($date); echo "Date Submited: $date<br>"; // with stripdash $timestamp = strtotime ($date); $new_date = getdate ($timestamp); echo "Date Computed: ".$new_date['month']." ".$new_date['mday'].", ".$new_date['year']."<br>"; echo "Timestamp Computed: $timestamp<br>"; } ?> <form name="form1" method="post" action=""> Date:<br> <input name="field" type="text"> <input type="submit" name="Submit" value="Submit"> </form> </body> </html> This script will display -1 if it encounters a date out of range (< 1903 or > 2038) or in some cases where century (yyyy) is needed to calculate the timestamp. Thanks to irmak for the idea.

« previous php.notes (#59000) next »