Title: Date validation
Last modified: August 21, 2016

---

# Date validation

 *  Resolved [newslines](https://wordpress.org/support/users/newslines/)
 * (@newslines)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/date-validation/)
 * Hi, will this plugin validate dates? Will I need code to do the following?
    I
   want to be able to ask posters to re-enter the date if the date they enter is
   greater than today’s date. In other words if they input tomorrow’s date or any
   other future date they will fail validation.
 * [https://wordpress.org/plugins/validated-field-for-acf/](https://wordpress.org/plugins/validated-field-for-acf/)

Viewing 1 replies (of 1 total)

 *  Plugin Author [doublesharp](https://wordpress.org/support/users/doublesharp/)
 * (@doublesharp)
 * [11 years, 11 months ago](https://wordpress.org/support/topic/date-validation/#post-5005404)
 * Yes, it can validate a date using the PHP validation – really you can do pretty
   much anything you want with the PHP using the `$value` argument. StackOverflow
   is a great place to look for help with questions like these, but all you need
   to do is convert the String to a Date using [`strtotime()`](http://www.php.net//manual/en/function.strtotime.php)
   and then do the comparison using the results of [`date()`](http://us1.php.net/manual/en/function.date.php).
 *     ```
       // make sure the date isn't empty and is in the format yyyy-dd-mm or change for your format
       if ( empty( $value ) || ! preg_match( '~\d{4,4}-\d{2,2}-\d{2,2}~", $value){
           $message = 'You must enter a valid date';
           return false;
       } else {
           $input_date = strtotime( $value ); // input date in seconds
           $today_str = date( 'Y-m-d' );      // date as string based on current timestamp
           $today = strtotime( $today_str );  // today's date on the server in seconds for comparison
           if ( $today < $input_date ){
               $message = 'The date cannot be in the future. Today is ' . $today_str . ' and you entered ' . $value;
               return false;
           } elseif ( $today == $input_date ){
               return true; // the date is today
           } elseif ( $today > $input_date ){
               return true; // the date is in the past
           }
       }
       ```
   

Viewing 1 replies (of 1 total)

The topic ‘Date validation’ is closed to new replies.

 * ![](https://ps.w.org/validated-field-for-acf/assets/icon-256x256.png?rev=1116693)
 * [Advanced Custom Fields: Validated Field](https://wordpress.org/plugins/validated-field-for-acf/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/validated-field-for-acf/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/validated-field-for-acf/)
 * [Active Topics](https://wordpress.org/support/plugin/validated-field-for-acf/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/validated-field-for-acf/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/validated-field-for-acf/reviews/)

## Tags

 * [dates](https://wordpress.org/support/topic-tag/dates/)
 * [validation](https://wordpress.org/support/topic-tag/validation/)

 * 1 reply
 * 2 participants
 * Last reply from: [doublesharp](https://wordpress.org/support/users/doublesharp/)
 * Last activity: [11 years, 11 months ago](https://wordpress.org/support/topic/date-validation/#post-5005404)
 * Status: resolved