Liam Dawe Liam Dawe - 1 year ago 91
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.

Answer Source

You can try using DateTime::createFromFormat()

$notValid = DateTime::createFromFormat('F Y', '21 January 2016'); // false
$valid = DateTime::createFromFormat('F Y', 'January 2016'); // DateTime object
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download