Reputation: 519
I have an input field for 'birthday' I'm using a javascript popup that returns the date in the following format "MM-DD'YYYY", when I bring echo the value in the input field in my insert code, it displays properly, but when I use
$c_birthday = $_POST['dateBorn'];
$birth=date('Y.m.d',strtotime($c_birthday));
If I echo $c_birthday, it displays the value correctly such as "10-02-2012" but when I echo $birth, it shows 2012-02-10, it's transposing the day and the month, I've tried using 'Y-m-d' and I get the same results.
Is there a setting I should be looking at?
Upvotes: 0
Views: 72
Reputation: 95101
Note:
Dates in the m/d/y or d-m-y formats are disambiguated by looking at the separator between the various components: if the separator is a slash (/), then the American m/d/y is assumed; whereas if the separator is a dash (-) or a dot (.), then the European d-m-y format is assumed.
To avoid potential ambiguity, it's best to use ISO 8601 (YYYY-MM-DD) dates or DateTime::createFromFormat() when possible.
To avoid potential ambiguity
as stated you can just use :
$dt = DateTime::createFromFormat("m-d-Y", $c_birthday);
$dt->format("Y.m.d");
Upvotes: 4