That format isn't one that strtotime()
recognizes. Use DateTime::createFromFormat()
instead:
$newdate = DateTime::createFromFormat('l, j F, Y', 'Wednesday, 30 April, 2014');
echo $newdate->format('Y-m-d');
Pergunta
Im using datepicker in my input to select the date.
Im my datepicker script I set a format to my date, like this:
$('.datepicker').datepicker({
dateFormat: 'DD, d MM, yy',
});
The result of this is "Wednesday, 30 April, 2014".
But now I want to save this text date in my sql table as datetime so I need to do the conversion.
Im Trying like this:
$f['date'] = $_POST['date'];
$newdate = date('Y-m-d', strtotime($f['date']));
echo $newdate;
But When I do the echo it shows always: "1970-01-01"
My input:
<input type="text" class="datepicker" name="date" value="" />
Solução
That format isn't one that strtotime()
recognizes. Use DateTime::createFromFormat()
instead:
$newdate = DateTime::createFromFormat('l, j F, Y', 'Wednesday, 30 April, 2014');
echo $newdate->format('Y-m-d');