Osman
Osman

Reputation: 1771

php strtotime() messes with date of a different year

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?

Upvotes: 6

Views: 943

Answers (1)

user1726343
user1726343

Reputation:

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")

Upvotes: 7

Related Questions