Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php strtotime() messes with date of a different year

Tags:

php

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?

like image 238
Osman Avatar asked Oct 30 '12 06:10

Osman


People also ask

Why is Strtotime return false?

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.

How does Strtotime work in PHP?

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.

How do you get a date from Strtotime?

Code for converting a string to dateTime$date = strtotime ( $input ); echo date ( 'd/M/Y h:i:s' , $date );


1 Answers

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")
like image 159
Asad Saeeduddin Avatar answered Sep 22 '22 08:09

Asad Saeeduddin