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 or
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::HOURMethodDescriptionOriginal dateResultget(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 or time has a unique constant in Zend_Date.
All constants supported by Zend_Date are listed below.
Day ConstantsConstantDescriptionDateResultZend_Date::DAYDay (as number, two digits)2009-02-13T14:53:27+01:0013Zend_Date::DAY_SHORTDay (as number, one or two digits)2009-02-06T14:53:27+01:006Zend_Date::WEEKDAYWeekday (Name of the day, localized, complete)2009-02-13T14:53:27+01:00FridayZend_Date::WEEKDAY_SHORT
Weekday (Name of the day, localized, abbreviated, two to four chars)
2009-02-13T14:53:27+01:00Fri for FridayZend_Date::WEEKDAY_NAME
Weekday (Name of the day, localized, abbreviated, one or two chars)
2009-02-13T14:53:27+01:00Fr for FridayZend_Date::WEEKDAY_NARROW
Weekday (Name of the day, localized, abbreviated, one char)
2009-02-13T14:53:27+01:00F for FridayZend_Date::WEEKDAY_DIGITWeekday (0 = Sunday, 6 = Saturday)2009-02-13T14:53:27+01:005 for FridayZend_Date::WEEKDAY_8601
Weekday according to ISO 8601 (1 = Monday, 7 =
Sunday)
2009-02-13T14:53:27+01:005 for FridayZend_Date::DAY_OF_YEARDay (as a number, one or two digits)2009-02-13T14:53:27+01:0043Zend_Date::DAY_SUFFIXEnglish addendum for the day (st, nd, rd, th)2009-02-13T14:53:27+01:00th
Month ConstantsConstantDescriptionDateResultZend_Date::MONTH_NAMEMonth (Name of the month, localized, complete)2009-02-13T14:53:27+01:00FebruaryZend_Date::MONTH_NAME_SHORT
Month (Name of the month, localized, abbreviated, two to four chars)
2009-02-13T14:53:27+01:00FebZend_Date::MONTH_NAME_NARROW
Month (Name of the month, localized, abbreviated, one or two chars)
2009-02-13T14:53:27+01:00FZend_Date::MONTHMonth (Number of the month, two digits)2009-02-13T14:53:27+01:0002Zend_Date::MONTH_SHORTMonth (Number of the month, one or two digits)2009-02-13T14:53:27+01:002Zend_Date::MONTH_DAYSNumber of days for this month (number)2009-02-13T14:53:27+01:0028
Year ConstantsConstantDescriptionDateResultZend_Date::YEARYear (number)2009-02-13T14:53:27+01:002009Zend_Date::YEAR_8601Year according to ISO 8601 (number)2009-02-13T14:53:27+01:002009Zend_Date::YEAR_SHORTYear (number, two digits)2009-02-13T14:53:27+01:0009Zend_Date::YEAR_SHORT_8601
Year according to ISO 8601 (number, two digits)
2009-02-13T14:53:27+01:0009Zend_Date::LEAPYEAR
Is the year a leap year? (TRUE or
FALSE)
2009-02-13T14:53:27+01:00FALSE
Time ConstantsConstantDescriptionDateResultZend_Date::HOURHour (00-23, two digits)2009-02-13T14:53:27+01:0014Zend_Date::HOUR_SHORTHour (0-23, one or two digits)2009-02-13T14:53:27+01:0014Zend_Date::HOUR_SHORT_AMHour (1-12, one or two digits)2009-02-13T14:53:27+01:002Zend_Date::HOUR_AMHour (01-12, two digits)2009-02-13T14:53:27+01:0002Zend_Date::MINUTEMinute (00-59, two digits)2009-02-13T14:53:27+01:0053Zend_Date::MINUTE_SHORTMinute (0-59, one or two digits)2009-02-13T14:03:27+01:003Zend_Date::SECONDSecond (00-59, two digits)2009-02-13T14:53:27+01:0027Zend_Date::SECOND_SHORTSecond (0-59, one or two digits)2009-02-13T14:53:07+01:007Zend_Date::MILLISECONDMillisecond (theoretically infinite)2009-02-06T14:53:27.2054620546Zend_Date::MERIDIEMTime of day (forenoon or afternoon)2009-02-13T14:53:27+01:00afternoonZend_Date::SWATCHSwatch Internet Time2009-02-13T14:53:27+01:00620
Timezone ConstantsConstantDescriptionDateResultZend_Date::TIMEZONEName der time zone (string, abbreviated)2009-02-13T14:53:27+01:00CETZend_Date::TIMEZONE_NAMEName of the time zone (string, complete)2009-02-13T14:53:27+01:00Europe/ParisZend_Date::TIMEZONE_SECS
Difference of the time zone to GMT in seconds
(integer)
2009-02-13T14:53:27+01:003600 (seconds to GMT)Zend_Date::GMT_DIFFDifference to GMT in seconds (string)2009-02-13T14:53:27+01:00+0100Zend_Date::GMT_DIFF_SEP
Difference to GMT in seconds (string, separated)
2009-02-13T14:53:27+01:00+01:00Zend_Date::DAYLIGHT
Summer time or Winter time? (TRUE or
FALSE)
2009-02-13T14:53:27+01:00FALSE
Date Format Constants (formats include timezone)ConstantDescriptionDateResultZend_Date::ISO_8601
Date 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::RFC_3339Date according to RFC 3339 (string)2009-02-13T14:53:27+01:002009-02-13T14:53:27+01:00Zend_Date::RSSDate for RSS Feeds (string)2009-02-13T14:53:27+01:00Fri, 13 Feb 2009 14:53:27 +0100Zend_Date::W3C
Date for HTML or 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)ConstantDescriptionDateResultZend_Date::ERAEpoch (string, localized, abbreviated)2009-02-13T14:53:27+01:00AD (anno Domini)Zend_Date::ERA_NAMEEpoch (string, localized, complete)2009-02-13T14: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:53Zend_Date::DATETIMEStandard date with time (string, localized, default value).2009-02-13T14:53:27+01:0013.02.2009 14:53:27Zend_Date::DATETIME_FULLComplete date with time (string, localized, complete)2009-02-13T14:53:27+01:00Friday, 13. February 2009 14:53 Uhr
CETZend_Date::DATETIME_LONGLong date with time (string, localized, long)2009-02-13T14:53:27+01:0013. February 2009 14:53:27 CETZend_Date::DATETIME_MEDIUMNormal date with time (string, localized, normal)2009-02-13T14:53:27+01:0013.02.2009 14:53:27Zend_Date::DATETIME_SHORTAbbreviated date with time (string, localized, abbreviated)2009-02-13T14:53:27+01:0013.02.09 14: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 Self-Defined OUTPUT
Formats Using PHP's date() Format Specifiers below).
Self-Defined ISO FormatstoString("'Era:GGGG='GGGG, ' Date:yy.MMMM.dd'yy.MMMM.dd");
]]>
Constants for ISO 8601 Date OutputConstantDescriptionCorresponds best toResultGEpoch, 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::YEAR02009Y
Year according to ISO 8601, at least one digit
Zend_Date::YEAR_86019YY
Year according to ISO 8601, at least two digit
Zend_Date::YEAR_SHORT_860109YYY
Year according to ISO 8601, at least three digit
Zend_Date::YEAR_86012009YYYY
Year according to ISO 8601, at least four digit
Zend_Date::YEAR_86012009YYYYY
Year according to ISO 8601, at least five digit
Zend_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 or more charsZend_Date::WEEKDAY_NAMEMoEEEDay of the week, localized, abbreviated, three charsZend_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_DIGIT4eeNumber 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:00AMilliseconds from the actual dayZend_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");
]]>PHP Date format and using constants
It is important to note that Zend_Date's constants are
using the ISO notation. This means, that when you set
Zend_Date to use the PHP notation,
you should not use Zend_Date's constants, but define the
wished format manually. If you don't follow this recommendation, you can get
unexpected results.
The following table shows the list of PHP date format specifiers with
their equivalent Zend_Date constants and
CLDR and ISO equivalent format specifiers. In most
cases, when the CLDR and 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 equivalentResultdDay 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 equivalentTRUEo
Year according to ISO 8601, at least four digit
Zend_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-13T15:19:21+00:00rStandard Rfc 2822 format outputZend_Date::RFC_2822no equivalentThu, 21 Dec 2000 16:01:07 +0200UUnix timestampZend_Date::TIMESTAMPno equivalent15275422364