jasonc Posted April 27, 2010 Share Posted April 27, 2010 i wish to know how i can validate a date which is formated..... 2010-04-27 yyyy-mm-dd and also that it is an actual date. Quote Link to comment https://forums.phpfreaks.com/topic/199960-how-to-validate-a-date-is-formatted-correctly/ Share on other sites More sharing options...
PFMaBiSmAd Posted April 27, 2010 Share Posted April 27, 2010 <?php $date = "2010-04-27"; // yyyy-mm-dd if (preg_match('/^(\d{4})-(\d{2})-(\d{2})/', $date, $regs)) { echo "$date is a valid format.<br />"; if(checkdate($regs[2], $regs[3], $regs[1])) { echo "$date is a valid date.<br />"; // the $date is both a value format and a valid date } else { echo "$date is not a valid date.<br />"; } } else { echo "$date is not a valid format.<br />"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/199960-how-to-validate-a-date-is-formatted-correctly/#findComment-1049516 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.