JavaQueen JavaQueen - 1 year ago 103
PHP Question

DateFromFormat returns an empty value

I try to verify and correct the date format by this code:

<?php
$date = DateTime::createFromFormat('Ymd', '15-Feb-2009');
echo $date;
?>


My issue is that
$date
is empty. I can't get any return from the
createFromFormat
function.

Answer Source

It should be like:

<?php
$date = date_create_from_format('j-M-Y', '15-Feb-2009');
echo date_format($date, 'Y-m-d');  //prints 2009-02-15
?>

date_create_from_format () Returns a new DateTime object representing the date and time specified by the time string, which was formatted in the given format.

DateTime date_create_from_format ( string $format , string $time [, DateTimeZone $timezone ] )
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download