Liam Dawe Liam Dawe - 8 months ago 31
PHP Question

php detect if date given has no day value

Say I am given a date like "August 2016" is there a way in PHP to simply find if a date has no day given?

All the PHP functions I can find automatically set a "1" to the day of a date if none is given.

What I want to do is weed out dates that don't give me a day.

They are not provided by me, and can be mixed in UK or US formats.


You can try using DateTime::createFromFormat()

$notValid = DateTime::createFromFormat('F Y', '21 January 2016'); // false
$valid = DateTime::createFromFormat('F Y', 'January 2016'); // DateTime object