note 78988 modified in function.strtotime by danbrown
| From: | danbrown@php.net | Date: | Mon, 18 May 2009 02:23:08 +0000 |
| Subject: | note 78988 modified in function.strtotime by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-155650@lists.php.net to get a copy of this message | ||
strtotime() reads the timestamp in en_US format if you want to change the date format with this
number, you should previously know the format of the date you are trying to parse. Let's say
you want to do this :
<?php strftime("%Y-%m-%d",strtotime("05/11/2007")); ?>
It will understand the date as 11th of may 2007, and not 5th of november 2007. In this case I would
use:
<?php
$date = explode("/","05/11/2007");
strftime("%Y-%m-%d",mktime(0,0,0,$date[1],$date[0],$date[2]));
?>
Much reliable but you must know the date format before. You can use javascript to mask the date
field and, if you have a calendar in your page, everything is done.
Thank you.
--was--
strtotime() reads the timestamp in en_US format if you want to change the date format with this
number, you should previously know the format of the date you are trying to parse. Let's say
you want to do this :
strftime("%Y-%m-%d",strtotime("05/11/2007"));
It will understand the date as 11th of may 2007, and not 5th of november 2007. In this case I would
use:
$date = explode("/","05/11/2007");
strftime("%Y-%m-%d",mktime(0,0,0,$date[1],$date[0],$date[2]));
Much reliable but you must know the date format before. You can use javascript to mask the date
field and, if you have a calendar in your page, everything is done.
Thank you.
http://php.net/manual/en/function.strtotime.php