Constants for General Date Functions
Whenever a Zend_Date method has a $parts parameter, one of the constants below can be
used as the argument for that parameter, in order to select a specific part of a date or indicate the date
format used or desired (e.g. RFC 822).
Using Constants
For example, the constant Zend_Date::HOUR can be used in the ways shown below. When working
with days of the week, calendar dates, hours, minutes, seconds, and any other date parts that are expressed
differently when in different parts of the world, the object's timezone will automatically be used to
compute the correct value, even though the internal timestamp is the same for the same moment in time,
regardless of the user's physical location in the world. Regardless of the units involved, output must be
expressed either as GMT/UTC or localized to a locale. The example output below reflects localization to
Europe/GMT+1 hour (e.g. Germany, Austria, France).
Operations Involving Zend_Date::HOURFunction/inputDescriptionOriginal dateEffect/outputget(Zend_Date::HOUR)Output of the hour2009-02-13T14:53:27+01:0014set(12, Zend_Date::HOUR)Set new hour2009-02-13T14:53:27+01:002009-02-13T12:53:27+01:00add(12, Zend_Date::HOUR)Add hours2009-02-13T14:53:27+01:002009-02-14T02:53:27+01:00sub(12, Zend_Date::HOUR)Subtract hours2009-02-13T14:53:27+01:002009-02-13T02:53:27+01:00compare(12, Zend_Date::HOUR)Compare hour, returns 0, 1 or -12009-02-13T14:53:27+01:001 (if object > argument)copy(Zend_Date::HOUR)Copies only the hour part2009-02-13T14:53:27+01:001970-01-01T14:00:00+01:00equals(14, Zend_Date::HOUR)Compares the hour, returns TRUE or FALSE2009-02-13T14:53:27+01:00TRUEisEarlier(12, Zend_Date::HOUR)Compares the hour, returns TRUE or FALSE2009-02-13T14:53:27+01:00TRUEisLater(12, Zend_Date::HOUR)Compares the hour, returns TRUE or FALSE2009-02-13T14:53:27+01:00FALSE
List of All Constants
Each part of a date/time has a unique constant in Zend_Date. All constants supported by
Zend_Date are listed below.
Day ConstantsConstantDescriptionDateAffected part/exampleZend_Date::DAYDay (as a number, two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00 (06)Zend_Date::DAY_SHORTDay (as a number, one or two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00 (6)Zend_Date::WEEKDAYWeekday (Name of the day, localized, complete)2009-02-06T14:53:27+01:00FridayZend_Date::WEEKDAY_SHORTWeekday (Name of the day, localized, abbreviated, the first three digits)2009-02-06T14:53:27+01:00Fri for FridayZend_Date::WEEKDAY_NAMEWeekday (Name of the day, localized, abbreviated, the first two digits)2009-02-06T14:53:27+01:00Fr for FridayZend_Date::WEEKDAY_NARROWWeekday (Name of the day, localized, abbreviated, only the first digit)2009-02-06T14:53:27+01:00F for FridayZend_Date::WEEKDAY_DIGITWeekday (0 = Sunday, 6 = Saturday)2009-02-06T14:53:27+01:005 for FridayZend_Date::WEEKDAY_8601Weekday according to ISO 8601 (1 = Monday, 7 = Sunday)2009-02-06T14:53:27+01:005 for FridayZend_Date::DAY_OF_YEARDay (as a number, one or two digit)2009-02-06T14:53:27+01:0043Zend_Date::DAY_SUFFIXEnglish addendum for the day (st, nd, rd, th)2009-02-06T14:53:27+01:00th
Week ConstantsConstantDescriptionDateAffected part/exampleZend_Date::WEEKWeek (as a number, 1-53)2009-02-06T14:53:27+01:007
Month ConstantsConstantDescriptionDateAffected part/exampleZend_Date::MONTH_NAMEMonth (Name of the month, localized, complete)2009-02-06T14:53:27+01:00FebruaryZend_Date::MONTH_NAME_SHORTMonth (Name of the month, localized, abbreviated, three digit)2009-02-06T14:53:27+01:00FebZend_Date::MONTH_NAME_NARROWMonth (Name of the month, localized, abbreviated, one digit)2009-02-06T14:53:27+01:00FZend_Date::MONTHMonth (Number of the month, two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00 (02)Zend_Date::MONTH_SHORTMonth (Number of the month, one or two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00 (2)Zend_Date::MONTH_DAYSNumber of days for this month (number)2009-02-06T14:53:27+01:0028
Year ConstantsConstantDescriptionDateAffected part/exampleZend_Date::YEARYear (number)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00Zend_Date::YEAR_8601Year according to ISO 8601 (number)2009-02-06T14:53:27+01:002009Zend_Date::YEAR_SHORTYear (number, two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00Zend_Date::YEAR_SHORT_8601Year according to ISO 8601 (number, two digit)2009-02-06T14:53:27+01:0009Zend_Date::LEAPYEARIs the year a leap year? (TRUE or FALSE)2009-02-06T14:53:27+01:00FALSE
Time ConstantsConstantDescriptionDateAffected part/exampleZend_Date::HOURHour (00-23, two digit)2009-02-06T14:53:27+01:0014Zend_Date::HOUR_SHORTHour (0-23, one or two digit)2009-02-06T14:53:27+01:0014Zend_Date::HOUR_SHORT_AMHour (1-12, one or two digit)2009-02-06T14:53:27+01:002Zend_Date::HOUR_AMHour (01-12, two digit)2009-02-06T14:53:27+01:0002Zend_Date::MINUTEMinute (00-59, two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00Zend_Date::MINUTE_SHORTMinute (0-59, one or two digit)2009-02-06T14:03:27+01:002009-02-06T14:03:27+01:00Zend_Date::SECONDSecond (00-59, two digit)2009-02-06T14:53:27+01:002009-02-06T14:53:27+01:00Zend_Date::SECOND_SHORTSecond (0-59, one or two digit)2009-02-06T14:53:07+01:002009-02-06T14:53:07+01:00Zend_Date::MILLISECONDMillisecond (theoretically infinite)2009-02-06T14:53:27.205462009-02-06T14:53:27.20546Zend_Date::MERIDIEMTime of day (forenoon/afternoon)2009-02-06T14:53:27+01:00afternoonZend_Date::SWATCHSwatch Internet Time2009-02-06T14:53:27+01:00620
Timezone ConstantsConstantDescriptionDateAffected part/exampleZend_Date::TIMEZONEName der time zone (string, abbreviated)2009-02-06T14:53:27+01:00CETZend_Date::TIMEZONE_NAMEName of the time zone (string, complete)2009-02-06T14:53:27+01:00Europe/ParisZend_Date::TIMEZONE_SECSDifference of the time zone to GMT in seconds (integer)2009-02-06T14:53:27+01:003600 seconds to GMTZend_Date::GMT_DIFFDifference to GMT in seconds (string)2009-02-06T14:53:27+01:00+0100Zend_Date::GMT_DIFF_SEPDifference to GMT in seconds (string, separated)2009-02-06T14:53:27+01:00+01:00Zend_Date::DAYLIGHTSummer time or Winter time? (TRUE or FALSE)2009-02-06T14:53:27+01:00FALSE
Date Format Constants (formats include timezone)ConstantDescriptionDateAffected part/exampleZend_Date::ISO_8601Date according to ISO 8601 (string, complete)2009-02-13T14:53:27+01:002009-02-13T14:53:27+01:00Zend_Date::RFC_2822Date according to RFC 2822 (string)2009-02-13T14:53:27+01:00Fri, 13 Feb 2009 14:53:27 +0100Zend_Date::TIMESTAMPUnix time (seconds since 1.1.1970, mixed)2009-02-13T14:53:27+01:001234533207Zend_Date::ATOMDate according to ATOM (string)2009-02-13T14:53:27+01:002009-02-13T14:53:27+01:00Zend_Date::COOKIEDate for Cookies (string, for Cookies)2009-02-13T14:53:27+01:00Friday, 13-Feb-09 14:53:27 Europe/ParisZend_Date::RFC_822Date according to RFC 822 (string)2009-02-13T14:53:27+01:00Fri, 13 Feb 09 14:53:27 +0100Zend_Date::RFC_850Date according to RFC 850 (string)2009-02-13T14:53:27+01:00Friday, 13-Feb-09 14:53:27 Europe/ParisZend_Date::RFC_1036Date according to RFC 1036 (string)2009-02-13T14:53:27+01:00Fri, 13 Feb 09 14:53:27 +0100Zend_Date::RFC_1123Date according to RFC 1123 (string)2009-02-13T14:53:27+01:00Fri, 13 Feb 2009 14:53:27 +0100Zend_Date::RSSDate for RSS Feeds (string)2009-02-13T14:53:27+01:00Fri, 13 Feb 2009 14:53:27 +0100Zend_Date::W3CDate for HTML/HTTP according to W3C (string)2009-02-13T14:53:27+01:002009-02-13T14:53:27+01:00
Especially note Zend_Date::DATES, since this format specifier has a unique property within
Zend_Date as an input format specifier. When used as an
input format for $part, this constant provides the most flexible acceptance of a variety of
similar date formats. Heuristics are used to automatically extract dates from an input string and then "fix"
simple errors in dates (if any), such as swapping of years, months, and days, when possible.
Date and Time Formats (format varies by locale)ConstantDescriptionDateAffected part/exampleZend_Date::ERAEpoch (string, localized, abbreviated)2009-02-06T14:53:27+01:00AD (anno Domini)Zend_Date::ERA_NAMEEpoch (string, localized, complete)2009-02-06T14:53:27+01:00anno domini (anno Domini)Zend_Date::DATESStandard date (string, localized, default value).2009-02-13T14:53:27+01:0013.02.2009Zend_Date::DATE_FULLComplete date (string, localized, complete)2009-02-13T14:53:27+01:00Friday, 13. February 2009Zend_Date::DATE_LONGLong date (string, localized, long)2009-02-13T14:53:27+01:0013. February 2009Zend_Date::DATE_MEDIUMNormal date (string, localized, normal)2009-02-13T14:53:27+01:0013.02.2009Zend_Date::DATE_SHORTAbbreviated Date (string, localized, abbreviated)2009-02-13T14:53:27+01:0013.02.09Zend_Date::TIMESStandard time (string, localized, default value)2009-02-13T14:53:27+01:0014:53:27Zend_Date::TIME_FULLComplete time (string, localized, complete)2009-02-13T14:53:27+01:0014:53 Uhr CETZend_Date::TIME_LONGLong time (string, localized, Long)2009-02-13T14:53:27+01:0014:53:27 CETZend_Date::TIME_MEDIUMNormal time (string, localized, normal)2009-02-13T14:53:27+01:0014:53:27Zend_Date::TIME_SHORTAbbreviated time (string, localized, abbreviated)2009-02-13T14:53:27+01:0014:53
Self-Defined OUTPUT Formats with ISO
If you need a date format not shown above, then use a self-defined format composed from the ISO format token
specifiers below. The following examples illustrate the usage of constants from the table below to create
self-defined ISO formats. The format length is unlimited. Also, multiple usage of format constants is
allowed.
The accepted format specifiers can be changed from ISO Format to PHP's date format if you are more
comfortable with it. However, not all formats defined in the ISO norm are supported with PHP's date format
specifiers. Use the Zend_Date::setOptions(array('format_type' => 'php')) method to switch
Zend_Date methods from supporting ISO format specifiers to PHP date() type specifiers (see
below).
Self-Defined ISO FormatstoString("'Era:GGGG='GGGG, ' Date:yy.MMMM.dd'yy.MMMM.dd");
]]>
Constants for ISO 8601 Date OutputConstantDescriptionCorresponds best toAffected part/exampleGEpoch, localized, abbreviatedZend_Date::ERAADGGEpoch, localized, abbreviatedZend_Date::ERAADGGGEpoch, localized, abbreviatedZend_Date::ERAADGGGGEpoch, localized, completeZend_Date::ERA_NAMEanno dominiGGGGGEpoch, localized, abbreviatedZend_Date::ERAayYear, at least one digitZend_Date::YEAR9yyYear, at least two digitZend_Date::YEAR_SHORT09yyyYear, at least three digitZend_Date::YEAR2009yyyyYear, at least four digitZend_Date::YEAR2009yyyyyYear, at least five digitZend_Date::YEAR02009YYear according to ISO 8601, at least one digitZend_Date::YEAR_86019YYYear according to ISO 8601, at least two digitZend_Date::YEAR_SHORT_860109YYYYear according to ISO 8601, at least three digitZend_Date::YEAR_86012009YYYYYear according to ISO 8601, at least four digitZend_Date::YEAR_86012009YYYYYYear according to ISO 8601, at least five digitZend_Date::YEAR_860102009MMonth, one or two digitZend_Date::MONTH_SHORT2MMMonth, two digitZend_Date::MONTH02MMMMonth, localized, abbreviatedZend_Date::MONTH_NAME_SHORTFebMMMMMonth, localized, completeZend_Date::MONTH_NAMEFebruaryMMMMMMonth, localized, abbreviated, one digitZend_Date::MONTH_NAME_NARROWFwWeek, one or two digitZend_Date::WEEK5wwWeek, two digitZend_Date::WEEK05dDay of the month, one or two digitZend_Date::DAY_SHORT9ddDay of the month, two digitZend_Date::DAY09DDay of the year, one, two or three digitZend_Date::DAY_OF_YEAR7DDDay of the year, two or three digitZend_Date::DAY_OF_YEAR07DDDDay of the year, three digitZend_Date::DAY_OF_YEAR007EDay of the week, localized, abbreviated, one charZend_Date::WEEKDAY_NARROWMEEDay of the week, localized, abbreviated, two charZend_Date::WEEKDAY_NAMEMoEEEDay of the week, localized, abbreviated, three charZend_Date::WEEKDAY_SHORTMonEEEEDay of the week, localized, completeZend_Date::WEEKDAYMondayEEEEEDay of the week, localized, abbreviated, one digitZend_Date::WEEKDAY_NARROWMeNumber of the day, one digitZend_Date::WEEKDAY_NARROW4eeNumber of the day, two digitZend_Date::WEEKDAY_NARROW04aTime of day, localizedZend_Date::MERIDIEMvorm.hHour, (1-12), one or two digitZend_Date::HOUR_SHORT_AM2hhHour, (01-12), two digitZend_Date::HOUR_AM02HHour, (0-23), one or two digitZend_Date::HOUR_SHORT2HHHour, (00-23), two digitZend_Date::HOUR02mMinute, (0-59), one or two digitZend_Date::MINUTE_SHORT2mmMinute, (00-59), two digitZend_Date::MINUTE02sSecond, (0-59), one or two digitZend_Date::SECOND_SHORT2ssSecond, (00-59), two digitZend_Date::SECOND02SMillisecondZend_Date::MILLISECOND20536zTime zone, localized, abbreviatedZend_Date::TIMEZONECETzzTime zone, localized, abbreviatedZend_Date::TIMEZONECETzzzTime zone, localized, abbreviatedZend_Date::TIMEZONECETzzzzTime zone, localized, completeZend_Date::TIMEZONE_NAMEEurope/ParisZDifference of time zoneZend_Date::GMT_DIFF+0100ZZDifference of time zoneZend_Date::GMT_DIFF+0100ZZZDifference of time zoneZend_Date::GMT_DIFF+0100ZZZZDifference of time zone, separatedZend_Date::GMT_DIFF_SEP+01:00AMillisecondZend_Date::MILLISECOND20563
Note that the default ISO format differs from PHP's format which can be
irritating if you have not used in previous. Especially the format specifiers
for Year and Minute are often not used in the
intended way.
For year there are two specifiers available
which are often mistaken. The Y specifier
for the ISO year and the y specifier for the
real year. The difference is small but significant.
Y calculates the ISO year, which is often used
for calendar formats. See for example the 31. December 2007. The real year is
2007, but it is the first day of the first week in the week 1 of the year 2008.
So, if you are using 'dd.MM.yyyy' you will get '31.December.2007' but if you use
'dd.MM.YYYY' you will get '31.December.2008'. As you see this is no bug but a
expected behaviour depending on the used specifiers.
For minute the difference is not so big. ISO
uses the specifier m for the minute, unlike
PHP which uses i. So if you are getting no
minute in your format check if you have used the right specifier.
Self-Defined OUTPUT Formats Using PHP's date() Format Specifiers
If you are more comfortable with PHP's date format specifier than with ISO format specifiers, then you can
use the Zend_Date::setOptions(array('format_type' => 'php')) method to switch Zend_Date methods from
supporting ISO format specifiers to PHP date() type specifiers. Afterwards, all format parameters must be
given with
PHP's date() format specifiers
. The PHP date format lacks some of the formats supported by the ISO Format, and vice-versa. If you are not
already comfortable with it, then use the standard ISO format instead. Also, if you have legacy code using
PHP's date format, then either manually convert it to the ISO format using
Zend_Locale_Format::convertPhpToIsoFormat()
, or use setOptions(). The following examples illustrate the usage of constants from the table
below to create self-defined formats.
Self-Defined Formats with PHP Specifier 'php'));
$date = new Zend_Date(1234567890, false, $locale);
// outputs something like 'February 16, 2007, 3:36 am'
print $date->toString('F j, Y, g:i a');
print $date->toString("'Format:D M j G:i:s T Y='D M j G:i:s T Y");
]]>
The following table shows the list of PHP date format specifiers with their equivalent Zend_Date constants
and CLDR/ISO equivalent format specifiers. In most cases, when the CLDR/ISO format does not have an
equivalent format specifier, the PHP format specifier is not altered by
Zend_Locale_Format::convertPhpToIsoFormat(), and the Zend_Date methods then recognize these
"peculiar" PHP format specifiers, even when in the default "ISO" format mode.
Constants for PHP Date OutputConstantDescriptionCorresponds best toclosest CLDR equivalentAffected part/exampledDay of the month, two digitZend_Date::DAYdd09DDay of the week, localized, abbreviated, three digitZend_Date::WEEKDAY_SHORTEEEMonjDay of the month, one or two digitZend_Date::DAY_SHORTd9l (lowercase L)Day of the week, localized, completeZend_Date::WEEKDAYEEEEMondayNNumber of the weekday, one digitZend_Date::WEEKDAY_8601e4SEnglish suffixes for day of month, two charsno equivalentno equivalentstwNumber of the weekday, 0=sunday, 6=saturdayZend_Date::WEEKDAY_DIGITno equivalent4zDay of the year, one, two or three digitZend_Date::DAY_OF_YEARD7WWeek, one or two digitZend_Date::WEEKw5FMonth, localized, completeZend_Date::MONTH_NAMEMMMMFebruarymMonth, two digitZend_Date::MONTHMM02MMonth, localized, abbreviatedZend_Date::MONTH_NAME_SHORTMMMFebnMonth, one or two digitZend_Date::MONTH_SHORTM2tNumber of days per month, one or two digitsZend_Date::MONTH_DAYSno equivalent30LLeapyear, booleanZend_Date::LEAPYEARno equivalenttrueoYear according to ISO 8601, at least four digitZend_Date::YEAR_8601YYYY2009YYear, at least four digitZend_Date::YEARyyyy2009yYear, at least two digitZend_Date::YEAR_SHORTyy09aTime of day, localizedZend_Date::MERIDIEMa (sort of, but likely to be uppercase)vorm.ATime of day, localizedZend_Date::MERIDIEMa (sort of, but no guarantee that the format is uppercase)VORM.BSwatch internet timeZend_Date::SWATCHno equivalent1463gHour, (1-12), one or two digitZend_Date::HOUR_SHORT_AMh2GHour, (0-23), one or two digitZend_Date::HOUR_SHORTH2hHour, (01-12), two digitZend_Date::HOUR_AMhh02HHour, (00-23), two digitZend_Date::HOURHH02iMinute, (00-59), two digitZend_Date::MINUTEmm02sSecond, (00-59), two digitZend_Date::SECONDss02eTime zone, localized, completeZend_Date::TIMEZONE_NAMEzzzzEurope/ParisIDaylightZend_Date::DAYLIGHTno equivalent1ODifference of time zoneZend_Date::GMT_DIFFZ or ZZ or ZZZ+0100PDifference of time zone, separatedZend_Date::GMT_DIFF_SEPZZZZ+01:00TTime zone, localized, abbreviatedZend_Date::TIMEZONEz or zz or zzzCETZTime zone offset in secondsZend_Date::TIMEZONE_SECSno equivalent3600cStandard Iso format outputZend_Date::ISO_8601no equivalent2004-02-12T15:19:21+00:00rStandard Rfc 2822 format outputZend_Date::RFC_2822no equivalentThu, 21 Dec 2000 16:01:07 +0200UUnix timestampZend_Date::TIMESTAMPno equivalent15275422364