I have a date:
30/12/2010
I use:
DateTime::createFromFormat('d/m/Y', $input['date']);
But this outputs:
2010-12-30 21:15:37
How can I output just the date and not the time?
You can write a "!" before the format string.
DateTime::createFromFormat('!d/m/Y', $input['date']);
This will set the time to midnight.
In fact, your solution is in your question. createFromFormat method return to us a DateTime object.You can use it to print formatted date time.
$date = DateTime::createFromFormat('d/m/Y', $input['date']);
echo $date->format("Y-m-d");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With