Validating date in php

Cross-Browser Testing Tools/Services Web Functional/Regression Test Tools Web Site Security Test Tools External Site Monitoring Services Web Site Management Tools Log Analysis Tools Other Web Test Tools Note: Categories are not well-defined and some tools could have been listed in several categories; the 'Web Site Management Tools' category includes products that contain: site version control tools, combined utilities/tools, server management and optimization tools, and authoring/publishing/deployment tools that include significant site management or testing capabilities.Suggestions for category improvement are welcome; see bottom of this page to send suggestions.If you are still running an older version of PHP or are developing for Word Press, (Word Press’s minimum requirements are still 5.2.4 at the time of writing this), below is a very handy PHP date validator function I wrote.

/^(19[0-9]|2[0-9])\-(0[1-9]|1[0-2])\-(0[1-9]|1[0-9]|2[0-9]|3[0-1])((T|\s)(0[0-9]|1[0-9]|2[0-3])\:(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])\:(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])((\ |\.)[\d ])?

/** * Validates a string as a date in the inputted format.

* Version 1.0 * * @param type $date The date to check.

That being said, the basic PHP date validation technique is to use the checkdate function, like this: I hope this basic PHP date validation technique is helpful.

As mentioned, you'll probably want to add additional date validation checks to your algorithm, but this is the basic check to validate a date in PHP.

@whitej71 In the example you gave, it is correctly returning false.

You must have an account to comment. Please register or login here!