PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Testing Dates

Use checkDateFormat($inputString, array('date_format' => $format, $locale)) to check if a given string contains all expected date parts. The checkDateFormat() method uses getDate(), but without the option 'fixdate' to avoid returning TRUE when the input fails to conform to the date format. If errors are detected in the input, such as swapped values for months and days, the option 'fixdate' method will apply heuristics to "correct" dates before determining their validity.

Example 585. Date testing

<?php
$locale 
= new Zend_Locale('de_AT');
// using the default date format for 'de_AT', is this a valid date?
if (Zend_Locale_Format::checkDateFormat('13.Apr.2006',
                                        array(
'date_format' =>
                                                  
Zend_Locale_Format::STANDARD,
                                              
$locale)
                                       ) {
    print 
"date";
} else {
    print 
"not a date";
}

Zend Framework