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

Getting Dates and Date Parts

Several methods support retrieving values related to a Zend_Date instance.

Table 49. Date Output Methods

Method Explanation
toString()

toString($format = null, $locale = null)

Invoke directly or via the magic method __toString(). The toString() method automatically formats the date object's value according to the conventions of the object's locale, or an optionally specified $locale. For a list of supported format codes, see Self-Defined OUTPUT Formats with ISO.

toArray()

toArray()

Returns an array representation of the selected date according to the conventions of the object's locale. The returned array is equivalent to PHP's getdate() function and includes:

  • Number of day as 'day' (Zend_Date::DAY_SHORT)

  • Number of month as 'month' (Zend_Date::MONTH_SHORT)

  • Year as 'year' (Zend_Date::YEAR)

  • Hour as 'hour' (Zend_Date::HOUR_SHORT)

  • Minute as 'minute' (Zend_Date::MINUTE_SHORT)

  • Second as 'second' (Zend_Date::SECOND_SHORT)

  • Abbreviated timezone as 'timezone' (Zend_Date::TIMEZONE)

  • Unix timestamp as 'timestamp' (Zend_Date::TIMESTAMP)

  • Number of weekday as 'weekday' (Zend_Date::WEEKDAY_DIGIT)

  • Day of year as 'dayofyear' (Zend_Date::DAY_OF_YEAR)

  • Week as 'week' (Zend_Date::WEEK)

  • Delay of timezone to GMT as 'gmtsecs' (Zend_Date::GMT_SECS)

toValue()

toValue($part = null)

Returns an integer representation of the selected date $part according to the conventions of the object's locale. Returns FALSE when $part selects a non-numeric value, such as Zend_Date::MONTH_NAME_SHORT.

Limitation of toValue()

This method calls get() and casts the result to a PHP integer, which will give unpredictable results, if get() returns a numeric string containing a number too large for a PHP integer on your system. Use get() instead.

get()

get($part = null, $locale = null)

This method returns the $part of object's date localized to $locale as a formatted string or integer. See get() for more information.

now()

now($locale = null)

This convenience function is equivalent to new Zend_Date(). It returns the current date as a Zend_Date object, having $locale


Zend Framework