I am using php to reformat a date and post it to mysql. Everything works great until I pass dates for next year. For example Mon, 14 Jan, 2013
will be translated into 2012-01-16
. The format is correct just not the date, I have even tried changing the format I pass it, still no change. Here is what it gets Mon, 14 Jan, 2013
and here is the php that processes it:
$startdate = $_REQUEST['one'];
$start = date("Y-m-d", strtotime($startdate));
any clues as to why the hiccup happens only when we enter a new year, even past years?
strtotime expects a "English textual datetime" (according to the manual), which Y-D-M is not. Any time strtotime returns false, it simply doesn't understand your string, which in this application is expected.
The strtotime() function parses an English textual datetime into a Unix timestamp (the number of seconds since January 1 1970 00:00:00 GMT). Note: If the year is specified in a two-digit format, values between 0-69 are mapped to 2000-2069 and values between 70-100 are mapped to 1970-2000.
Code for converting a string to dateTime$date = strtotime ( $input ); echo date ( 'd/M/Y h:i:s' , $date );
Have a look here for the list of all valid formats for strtotime()
. The one you're using is not present.
If you want to use date_create_from_format
instead, here's how:
date_create_from_format("D, d M, Y", "Mon, 14 Jan, 2013")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With