PHP / Zend custom date input formats
Posted
by mld
on Stack Overflow
See other posts from Stack Overflow
or by mld
Published on 2010-05-24T15:57:18Z
Indexed on
2010/05/24
16:01 UTC
Read the original article
Hit count: 208
Hi,
I'm creating a library component for other developers on my team using PHP and Zend. This component needs to be able to take as input a date (string) and another string telling it the format of that date. Looking through the Zend documentation and examples, I thought I found the solution -
$dateObject = Zend_Date('13.04.2006', array('date_format' => 'dd.MM.yyyy'));
this line, however, throws an error - call to undefined function.
So instead I tried this -
$dt = Zend_Locale_Format::getDate('13.04.2006', array('date_format' => 'dd.MM.yyyy'));
This gets the job done, but throws an error if a date that is entered isn't valid. The docs make it look like you can use the isDate() function to check validity -
Zend_Date::isDate('13.04.2006', array('date_format' => 'dd.MM.yyyy'))
but this line always returns false.
So my questions -
Am I going about this the right way? If not, is there a better way to handle this via Zend or straight PHP?
If I do use Zend_Locale_Format::getDate(), do I need to worry about a locale being set elsewhere and changing the results of the call?
I'm locked into PHP 5.2.6 on windows, btw... so 5.3+ functions & strptime() are out.
© Stack Overflow or respective owner