Reputation: 9
I have created one form as following:
<form action="test.php" method="POST" name="edituser">
<input type="text" id="to_date_picker" placeholder="Select Date" name="todate" class="input" size="50" />
<input name="addnew" type="submit" value="Add & Save" id="submitbtn" />
</form>
<script type="text/javascript">
$(function() {
$('#to_date_picker').datepick();
});
</script>
test.php: is as following:
$todate = $_POST['todate'];
$newtodate = date("Y-m-d", strtotime($todate));
echo $newtodate."<br>\n";
here it is giving wrong output. here date picker is a calender from which date is picked.
Upvotes: 0
Views: 119
Reputation: 61
You can use new DateTime($todate); if you have PHP 5 >= 5.2.0 which is easier to use in my own opinion. Or if you don't want tu change the format return by your JavaScript, use the method DateTime::createFromFormat('j-M-Y', '15-Feb-2009'); which returns a DateTime object from a "custom" date (see documentation, link below).
Link : http://www.php.net/manual/fr/datetime.construct.php http://www.php.net/manual/fr/datetime.createfromformat.php
Upvotes: 0
Reputation: 4157
use this instead
$('#to_date_picker').datepick(
dateFormat: 'dd-mm-yy'
);
Upvotes: 0
Reputation: 103
You can search for mktime function, then you can parse your datetime for the proper format.
Upvotes: 0
Reputation:
What is your dateformat? Because the default dateformat for datepick is "mm/dd/yyyy". strtotime accept this format for date:
American month, day and year mm "/" dd "/" y "12/22/78", "1/17/2006", "1/17/6"
I think that your datepick returns 01/17/2006. Look for this.
Upvotes: 1