views:

104

answers:

3

Anybody can help me to get date formated with Zend framework

What I do is:

<?php echo new Zend_Date(2010-05-23, false, 'en');?>

Result I get is: May 22, 2010 12:00:00 AM

I what I need is: May 22, 2010

Thanks.

A: 

The date is returned as ISO standard date, unless you specify a format, as mentioned on the Zend Framework documentation on Zend_Data

A much easier solution would be:

 <?php echo date("F d, Y", strtotime(new Zend_Date(2010-05-23, false, 'en')));?>
Anthony
That gave me: Warning: date() expects parameter 2 to be long, object given in /Users/...Thanks anyway ;)
Trimm
`->getTimestamp()` on the `Zend_Date` should give you the long you can pass to `date()`
gnarf
sorry, I forgot that it was not returning it as an Epoch. Updated, should work.
Anthony
+2  A: 

You can use the string formatting options and constants:

// Using the strings for reading the format:
$date = new Zend_Date('2010-05-23', 'yyyy-MM-dd');
// Using the constants for format:
echo $date->toString(Zend_Date::MONTH_NAME." ".Zend_Date::DAY_SHORT.", ".Zend_Date::YEAR);
gnarf
Hey, thanks that is cool I think :) But is there any way to handle that with locale? I mean to get string formated by locale? Now I got this: "mayo 23, 2010" for Spanish locale and it is not correct :(
Trimm
@Trimm - Yes - the second argument to `toString()` can be a locale... try passing in 'en'
gnarf
@gnarf Perfect! Thats it :) Thank you very much.
Trimm
A: 

Only with Zend_Date...

$dateArray = array('year' => 2010, 'month' => 5, 'day' => 23);
$now = new Zend_Date($dateArray);
$date = $now->toString(Zend_Date::MONTH_NAME . ' ' . Zend_Date::DAY . ', ' . Zend_Date::YEAR);
Inkspeak