8.5. 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).

8.5.1. Using Constants

For example, the constant Zend_Date::HOUR can be used in the ways 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. Regardless of the units involved, output must be expressed either as GMT/UTC or localized to a locale. The example table below assumes the locale is Germany.

Tabela 8.4. Operations involving Zend_Date::HOUR

Function/input Description Original date Effect/output
get(Zend_Date::HOUR) Output of the hour 2009-02-13T14:53:27+01:00 14
set(12, Zend_Date::HOUR) Set new hour 2009-02-13T14:53:27+01:00 2009-02-13T12:53:27+01:00
add(12, Zend_Date::HOUR) Add hours 2009-02-13T14:53:27+01:00 2009-02-14T02:53:27+01:00
sub(12, Zend_Date::HOUR) Subtract hours 2009-02-13T14:53:27+01:00 2009-02-13T02:53:27+01:00
compare(12, Zend_Date::HOUR) Compare hour, returns 0, 1 or -1 2009-02-13T14:53:27+01:00 1 (Originalstunde ist größer)
copy(Zend_Date::HOUR) Copies only the hour part 2009-02-13T14:53:27+01:00 1970-01-01T14:00:00+01:00
equals(14, Zend_Date::HOUR) Compares the hour, returns TRUE or FALSE 2009-02-13T14:53:27+01:00 TRUE
isEarlier(12, Zend_Date::HOUR) Compares the hour, returns TRUE or FALSE 2009-02-13T14:53:27+01:00 TRUE
isLater(12, Zend_Date::HOUR) Compares the hour, returns TRUE or FALSE 2009-02-13T14:53:27+01:00 FALSE

8.5.2. 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.

Tabela 8.5. Day Constants

Constant Description Date Affected part/example
Zend_Date::DAY Day (as a number, two digit) 2009-02-06T14:53:27+01:00 2009-02-06T14:53:27+01:00 (06)
Zend_Date::DAY_SHORT Day (as a number, one or two digit) 2009-02-06T14:53:27+01:00 2009-02-06T14:53:27+01:00 (6)
Zend_Date::WEEKDAY Weekday (Name of the day, localized, complete) 2009-02-06T14:53:27+01:00 Friday
Zend_Date::WEEKDAY_SHORT Weekday (Name of the day, localized, abbreviated, the first three digits) 2009-02-06T14:53:27+01:00 Fre for Friday
Zend_Date::WEEKDAY_NAME Weekday (Name of the day, localized, abbreviated, the first two digits) 2009-02-06T14:53:27+01:00 Fr for Friday
Zend_Date::WEEKDAY_NARROW Weekday (Name of the day, localized, abbreviated, only the first digit) 2009-02-06T14:53:27+01:00 F for Friday
Zend_Date::WEEKDAY_DIGIT Weekday (0 = Sunday, 6 = Saturday) 2009-02-06T14:53:27+01:00 5 for Friday
Zend_Date::WEEKDAY_8601 Weekday according to ISO 8601 (1 = Monday, 7 = Sunday) 2009-02-06T14:53:27+01:00 5 for Friday
Zend_Date::DAY_OF_YEAR Day (as a number, one or two digit) 2009-02-06T14:53:27+01:00 43
Zend_Date::DAY_SUFFIX English addendum for the day (st, nd, rd, th) 2009-02-06T14:53:27+01:00 th

Tabela 8.6. Week Constants

Constant Description Date Affected part/example
Zend_Date::WEEK Week (as a number, 1-53) 2009-02-06T14:53:27+01:00 7

Tabela 8.7. Month Constants

Constant Description Date Affected part/example
Zend_Date::MONTH Month (Name of the month, localized, complete) 2009-02-06T14:53:27+01:00 February
Zend_Date::MONTH_NAME Month (Name of the month, localized, abbreviated, three digit) 2009-02-06T14:53:27+01:00 Feb
Zend_Date::MONTH_NARROW Month (Name of the month, localized, abbreviated, one digit) 2009-02-06T14:53:27+01:00 F
Zend_Date::MONTH_SHORT Month (Number of the month, two digit) 2009-02-06T14:53:27+01:00 2009-02-06T14:53:27+01:00 (02)
Zend_Date::MONTH_DIGIT Month (Number of the month, one or two digit) 2009-02-06T14:53:27+01:00 2009-02-06T14:53:27+01:00 (2)
Zend_Date::MONTH_DAYS Number of days for this month (number) 2009-02-06T14:53:27+01:00 28

Tabela 8.8. Year Constants

Constant Description Date Affected part/example
Zend_Date::YEAR Year (number) 2009-02-06T14:53:27+01:00 2009-02-06T14:53:27+01:00
Zend_Date::YEAR_8601 Year according to ISO 8601 (number) 2009-02-06T14:53:27+01:00 2009
Zend_Date::YEAR_SHORT Year (number, two digit) 2009-02-06T14:53:27+01:00 2009-02-06T14:53:27+01:00
Zend_Date::YEAR_SHORT_8601 Year according to ISO 8601 (number, two digit) 2009-02-06T14:53:27+01:00 09
Zend_Date::LEAPYEAR Is the year a leap year? (TRUE or FALSE) 2009-02-06T14:53:27+01:00 FALSE

Tabela 8.9. Time Constants

Constant Description Date Affected part/example
Zend_Date::HOUR Hour (00-23, two digit) 2009-02-06T14:53:27+01:00 14
Zend_Date::HOUR_SHORT Hour (0-23, one or two digit) 2009-02-06T14:53:27+01:00 14
Zend_Date::HOUR_AM Hour (1-12, one or two digit) 2009-02-06T14:53:27+01:00 2
Zend_Date::HOUR_SHORT_AM Hour (01-12, one or two digit) 2009-02-06T14:53:27+01:00 02
Zend_Date::MINUTE Minute (00-59, two digit) 2009-02-06T14:53:27+01:00 2009-02-06T14:53:27+01:00
Zend_Date::MINUTE_SHORT Minute (0-59, one or two digit) 2009-02-06T14:03:27+01:00 2009-02-06T14:03:27+01:00
Zend_Date::SECOND Second (00-59, two digit) 2009-02-06T14:53:27+01:00 2009-02-06T14:53:27+01:00
Zend_Date::SECOND_SHORT Second (0-59, one or two digit) 2009-02-06T14:53:07+01:00 2009-02-06T14:53:07+01:00
Zend_Date::MILLISECOND Millisecond (theoretically infinite) 2009-02-06T14:53:27.20546 2009-02-06T14:53:27.20546
Zend_Date::MERIDIEM Time of day (forenoon/afternoon) 2009-02-06T14:53:27+01:00 afternoon
Zend_Date::SWATCH Swatch Internet Time 2009-02-06T14:53:27+01:00 620

Tabela 8.10. Timezone Constants

Constant Description Date Affected part/example
Zend_Date::TIMEZONE Name der time zone (string, abbreviated) 2009-02-06T14:53:27+01:00 CET
Zend_Date::TIMEZONE_NAME Name of the time zone (string, complete) 2009-02-06T14:53:27+01:00 Europe/Paris
Zend_Date::TIMEZONE_SECS Difference of the time zone to GMT in seconds (integer) 2009-02-06T14:53:27+01:00 3600 seconds to GMT
Zend_Date::GMT_DIFF Difference to GMT in seconds (string) 2009-02-06T14:53:27+01:00 +0100
Zend_Date::GMT_DIFF_SEP Differenz to GMT in seconds (string, separated) 2009-02-06T14:53:27+01:00 2009-02-06T14:53:27+01:00
Zend_Date::DAYLIGHT Summertime or wintertime? (TRUE or FALSE) 2009-02-06T14:53:27+01:00 FALSE

Tabela 8.11. Date Format Constants (formats include timezone)

Constant Description Date Affected part/example
Zend_Date::ISO_8601 Date according to ISO 8601 (string, complete) 2009-02-13T14:53:27+01:00 2009-02-13T14:53:27+01:00
Zend_Date::RFC_2822 Date according to RFC 2822 (string) 2009-02-13T14:53:27+01:00 Fri, 13 Feb 2009 14:53:27 +0100
Zend_Date::TIMESTAMP Unix time (seconds since 1.1.1970, mixed) 2009-02-13T14:53:27+01:00 1234533207
Zend_Date::ATOM Date according to ATOM (string) 2009-02-13T14:53:27+01:00 2009-02-13T14:53:27+01:00
Zend_Date::COOKIE Date for Cookies (string, for Cookies) 2009-02-13T14:53:27+01:00 Friday, 13-Feb-09 14:53:27 Europe/Paris
Zend_Date::RFC_822 Date according to RFC 822 (string) 2009-02-13T14:53:27+01:00 Fri, 13 Feb 09 14:53:27 +0100
Zend_Date::RFC_850 Date according to RFC 850 (string) 2009-02-13T14:53:27+01:00 Friday, 13-Feb-09 14:53:27 Europe/Paris
Zend_Date::RFC_1036 Date according to RFC 1036 (string) 2009-02-13T14:53:27+01:00 Fri, 13 Feb 09 14:53:27 +0100
Zend_Date::RFC_1123 Date according to RFC 1123 (string) 2009-02-13T14:53:27+01:00 Fri, 13 Feb 2009 14:53:27 +0100
Zend_Date::RSS Date for RSS Feeds (string) 2009-02-13T14:53:27+01:00 Fri, 13 Feb 2009 14:53:27 +0100
Zend_Date::W3C Date for HTML/HTTP according to W3C (string) 2009-02-13T14:53:27+01:00 2009-02-13T14:53:27+01:00

Tabela 8.12. Date and Time Formats (format varies by locale)

Constant Description Date Affected part/example
Zend_Date::ERA Epoch (string, localized, abbreviated) 2009-02-06T14:53:27+01:00 AD (anno Domini)
Zend_Date::ERA_NAME Epoch (string, localized, complete) 2009-02-06T14:53:27+01:00 anno domini (anno Domini)
Zend_Date::DATES Standard date (string, localized, default value) 2009-02-13T14:53:27+01:00 13.02.2009
Zend_Date::DATE_FULL Complete date (string, localized, complete) 2009-02-13T14:53:27+01:00 Friday, 13. February 2009
Zend_Date::DATE_LONG Long date (string, localized, long) 2009-02-13T14:53:27+01:00 13. February 2009
Zend_Date::DATE_MEDIUM Normal date (string, localized, normal) 2009-02-13T14:53:27+01:00 13.02.2009
Zend_Date::DATE_SHORT Abbreviated Date (string, localized, abbreviated) 2009-02-13T14:53:27+01:00 13.02.09
Zend_Date::TIMES Standard time (string, localized, default value) 2009-02-13T14:53:27+01:00 14:53:27
Zend_Date::TIME_FULL Complete time (string, localized, complete) 2009-02-13T14:53:27+01:00 14:53 Uhr CET
Zend_Date::TIME_LONG Long time (string, localized, Long) 2009-02-13T14:53:27+01:00 14:53:27 CET
Zend_Date::TIME_MEDIUM Normal time (string, localized, normal) 2009-02-13T14:53:27+01:00 14:53:27
Zend_Date::TIME_SHORT Abbreviated time (string, localized, abbreviated) 2009-02-13T14:53:27+01:00 14:53

8.5.3. Self-Defined Formats

All formats which need to be self-defined correspond to the ISO 8601 norm. However, not all formats defined in the ISO norm are supported. Die format length is unlimited. Also the multiple usage of formats is allowed. The following example illustrates the usage of constants from the table below to create self-defined formats.

Exemplo 8.8. Example usage for self-defined formats

<?php
require_once 'Zend/Date.php';

$locale = new Zend_Locale('de_AT');
$date = new Zend_Date(1234567890, false, $locale);
print $date->toString("'Era:GGGG='GGGG, ' Date:yy.MMMM.dd'yy.MMMM.dd");
?>

Tabela 8.13. Constants for ISO 8601 date output

Constant Description Corresponds best to Affected part/example
G Epoch, localized, abbreviated Zend_Date::ERA AD
GG Epoch, localized, abbreviated Zend_Date::ERA AD
GGG Epoch, localized, abbreviated Zend_Date::ERA AD
GGGG Epoch, localized, complete Zend_Date::ERA_NAME anno domini
GGGGG Epoch, localized, abbreviated Zend_Date::ERA a
y Year, at least one digit Zend_Date::YEAR 9
yy Year, at least two digit Zend_Date::YEAR_SHORT 09
yyy Year, at least three digit Zend_Date::YEAR 2009
yyyy Year, at least four digit Zend_Date::YEAR 2009
yyyyy Year, at least five digit Zend_Date::YEAR 02009
Y Year according to ISO 8601, at least one digit Zend_Date::YEAR_8601 9
YY Year according to ISO 8601, at least two digit Zend_Date::YEAR_SHORT_8601 09
YYY Year according to ISO 8601, at least three digit Zend_Date::YEAR_8601 2009
YYYY Year according to ISO 8601, at least four digit Zend_Date::YEAR_8601 2009
YYYYY Year according to ISO 8601, at least five digit Zend_Date::YEAR_8601 02009
M Month, one or two digit Zend_Date::MONTH_DIGIT 2
MM Month, two digit Zend_Date::MONTH_SHORT 02
MMM Month, localized, abbreviated Zend_Date::MONTH_NAME Feb
MMMM Month, localized, complete Zend_Date::MONTH February
MMMMM Month, localized, abbreviated, one digit Zend_Date::MONTH_NARROW F
w Week, one or two digit Zend_Date::WEEK 5
ww Week, two digit Zend_Date::WEEK 05
d Day of the month, one or two digit Zend_Date::DAY_SHORT 9
dd Day of the month, two digit Zend_Date::DAY 09
D Day of the year, one, two or three digit Zend_Date::DAY_OF_YEAR 7
DD Day of the year, two or three digit Zend_Date::DAY_OF_YEAR 07
DDD Day of the year, three digit Zend_Date::DAY_OF_YEAR 007
E Day of the week, localized, abbreviated, one digit Zend_Date::WEEKDAY_NARROW M
EE Day of the week, localized, abbreviated, two digit Zend_Date::WEEKDAY_NAME Mo
EEE Day of the week, localized, abbreviated, three digit Zend_Date::WEEKDAY_SHORT Mon
EEEE Day of the week, localized, complete Zend_Date::WEEKDAY Monday
EEEEE Day of the week, localized, abbreviated, one digit Zend_Date::WEEKDAY_NARROW M
e Number of the day, one or two digit Zend_Date::WEEKDAY_NARROW 4
ee Number of the day, two digit Zend_Date::WEEKDAY_NARROW 04
a Time of day, localized Zend_Date::MERIDIEM vorm.
h Hour, (1-12), one or two digit Zend_Date::HOUR_SHORT_AM 2
hh Hour, (01-12), two digit Zend_Date::HOUR_AM 02
H Hour, (0-23), one or two digit Zend_Date::HOUR_SHORT 2
HH Hour, (00-23), two digit Zend_Date::HOUR 02
m Minute, (0-59), one or two digit Zend_Date::MINUTE_SHORT 2
mm Minute, (00-59), two digit Zend_Date::MINUTE 02
s Second, (0-59), one or two digit Zend_Date::SECOND_SHORT 2
ss Second, (00-59), two digit Zend_Date::SECOND 02
S Millisecond Zend_Date::MILLISECOND 20536
z Time zone, localized, abbreviated Zend_Date::TIMEZONE CET
zz Time zone, localized, abbreviated Zend_Date::TIMEZONE CET
zzz Time zone, localized, abbreviated Zend_Date::TIMEZONE CET
zzzz Time zone, localized, complete Zend_Date::TIMEZONE_NAME Europe/Paris
Z Difference of time zone Zend_Date::GMT_DIFF +0100
ZZ Difference of time zone Zend_Date::GMT_DIFF +0100
ZZZ Difference of time zone Zend_Date::GMT_DIFF +0100
ZZZZ Difference of time zone, separated Zend_Date::GMT_DIFF_SEP +01:00
A Millisecond Zend_Date::MILLISECOND 20563