JavaQueen JavaQueen - 4 years ago 158
PHP Question

DateFromFormat returns an empty value

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

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

My issue is that
is empty. I can't get any return from the

Answer Source

It should be like:

$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