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. 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 />"; } ?> 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
Archived
This topic is now archived and is closed to further replies.