How to check the validity of a date?

Hi Friends

I have a date in the form DD-MM-YYYY, I know how to explode it into just DD, MM and YYYY on its own but how do I check if this date is valid? For example 01-02-2009 is valid but 31-02-2009 is not.

Any way to check this?

Thanks

PHP has checkdate() for you

I’d use cal_days_in_month()


if($days >= 1 and $days <= cal_days_in_month(CAL_GREGORIAN, $month, $year))
{
  echo 'Days are valid.';
}

Though shrapnel’s might be better. :stuck_out_tongue: