Date - Maple Programming Help

Date

 Calling Sequence Date() Date( d ) Date( t ) Date( year, month, day, hour, minute, second, millisecond )

Parameters

 d - Date; a Date object t - Time ; a Time object year - integer; the year (required) month - integer; the number (1..12) of a month day - integer; the number of a day within the month month hour - integer; the hour (0..24) of the day minute - integer; the minute within the hour second - numeric; the second within the minute (may be fractional) millisecond - numeric; the millisecond within the second

Options

 • timezone : string; the name of a time zone

Description

 • The Date object represents a particular date and time in the Gregorian calendar. It represents a particular "view" of the a system UTC time, as represented by a Time object associated to the system UTC clock.
 • You can create a Date object by calling the Date constructor in several different ways.
 • Called without arguments, the Date() command returns the current date (and time of day) as reported by the system clock.
 • You can also pass an explicit UTC Time object t by calling the Date constructor in the form Date( t ).  This produces a Date object that represents the Time object t.
 • A Date object d can be passed to the Date constructor in the form Date( d ), producing a new Date object that represents the same moment in time as the original Date object d.  This is most useful when used in conjunction with the timezone= option to convert between different time zones.
 • The Date constructor also takes specific components: year, month, day, hour, minute, second and millisecond. These must be passed in the stated order, but all components after the year are optional in the sense that any initial sub-sequence of these may be passed with the values for omitted components being set to their default values. The default values for components after the year are all $0$, except for hour, for which the default values is $12$ (representing noon). However, you cannot specify any particular component without specifying all the components before it in the sequence. For example, to pass the hour component, you must also specify the year, month and day components (in that order) first.
 • The year value year must be in the range $-9223372036854775808\le \mathrm{year}\le 9223372036854775807$ on $64$-bit platforms. On $32$-bit platforms, the year is limited to the range $-4294967296\le \mathrm{year}\le 4294967295$.

Methods

 • Date objects support a number of methods.

 Year  the year of the Date object Month  the (numeric) month within the year DayOfMonth  the (numeric) day of the month HourOfDay  the hour of the day Minute  the minute within the hour Second  the seconds within the minute TimeZone  the time zone of the Date object (by default, "UTC") Precision  the precision of the Date object; normally the precision of the underlying Clock

 • The Year( d ) command returns the (integer) year of the Date object d.
 • The Month( d ) command returns the numeric month of the Date object d. This is an integer in the range 1 .. 12, with $1$ denoting January, $2$ denoting February, and so on.
 • The (integer) day of the month of the Date object d is returned by the command DayOfMonth( d ).  This is a positive integer, no larger than the last day of the month represented by d.
 • The HourOfDay( d ) command returns an integer in the range 0 .. 24 denoting the hour of the day represented by d (that is, a $24$-hour clock). Note that an hour equal to $24$ is equivalent to the $0$th hour of the next day.
 • The minute of the hour represented by d is returned by the command Minute( d ).
 • The Second( d ) command returns the number of seconds after the minute of d.
 • The default time zone of a Date object is the local time zone. The TimeZone( d ) command returns the time zone of d, which may be set explicitly via the timezone = T option.
 • Since a Date object is just a particular view onto a moment in time, represented by a Time object stored within the Date, it has an associated precision, which is equal to the precision of the underlying clock. In this case, the clock is the SystemUTCClock. The Precision( d ) command returns the precision associated with the Date object d.
 • In addition to the command-like methods listed above, arithmetic with Date objects is supported, as are comparisons using the operators < and <=.
 • To compute the length of time between two dates represented by Date objects d1 and d2, use the expression d1 - d2. More generally, a rational combination of Date objects with coefficients that sum to $0$ returns a unit expression of the time dimension.
 • Similarly, the midpoint between two Date objects d1 and d2 can be computed using the expression (d1 + d2) / 2. Again, more general rational combinations of Date objects with coefficient summing to $1$ return a new Date object representing a generalized "average" of those dates.
 • Other combinations of Date objects return unevaluated.
 • Note that leap seconds are ignored in all date and time arithmetic.

Examples

Create the current date in the default time zone.

 > $\mathrm{today}≔\mathrm{Date}\left(\right)$
 ${\mathrm{Date}}{}\left({2019}{,}{3}{,}{9}{,}{10}{,}{27}{,}\frac{{10971}}{{1000}}{,}{\mathrm{timezone}}{=}{"UTC"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (1)

Extract various components of the object.

 > $\mathrm{Year}\left(\mathrm{today}\right)$
 ${2019}$ (2)
 > $\mathrm{Month}\left(\mathrm{today}\right)$
 ${3}$ (3)
 > $\mathrm{Minute}\left(\mathrm{today}\right)$
 ${27}$ (4)

Create the current date in the local time zone.

 > $\mathrm{today}≔\mathrm{Date}\left(\mathrm{Now}\left(\mathrm{SystemUTCClock}\right),'\mathrm{timezone}'=\mathrm{Calendar}:-\mathrm{HostTimeZone}\left(\right)\right)$
 ${\mathrm{Date}}{}\left({2019}{,}{3}{,}{9}{,}{5}{,}{27}{,}{11}{,}{\mathrm{timezone}}{=}{"Canada/Eastern"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (5)

Create a specific date representing 3:42am on July 1, 1967.

 > $d≔\mathrm{Date}\left(1967,7,1,3,42\right)$
 ${\mathrm{Date}}{}\left({1967}{,}{7}{,}{1}{,}{3}{,}{42}{,}{0}{,}{\mathrm{timezone}}{=}{"Canada/Eastern"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (6)

How long has it been since that moment?

 > $\mathrm{today}-d$
 ${1631155511216}{}⟦{\mathrm{ms}}⟧$ (7)

Midnight (or any moment before 1am) can be specified either as the $24$th hour of one day, or the $0$th hour of the next day.

 > $\mathrm{d1}≔\mathrm{Date}\left(1999,3,14,24\right)$
 ${\mathrm{Date}}{}\left({1999}{,}{3}{,}{14}{,}{24}{,}{0}{,}{0}{,}{\mathrm{timezone}}{=}{"Canada/Eastern"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (8)
 > $\mathrm{d2}≔\mathrm{Date}\left(1999,3,15,0\right)$
 ${\mathrm{Date}}{}\left({1999}{,}{3}{,}{15}{,}{0}{,}{0}{,}{0}{,}{\mathrm{timezone}}{=}{"Canada/Eastern"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (9)
 > $\mathrm{d1}-\mathrm{d2}$
 ${0}$ (10)

To compute the length of the Second World War (taken from the invasion of Poland, at 4:45am on Sept. 1, 1939 to the formal surrender of Japan at about 9am on Sept. 2, 1945), construct the Date objects corresponding to the beginning and end events of the war, and subtract.

 > $\mathrm{d1}≔\mathrm{Date}\left(1939,9,1,4,45,'\mathrm{timezone}'="Europe/Berlin"\right)$
 ${\mathrm{Date}}{}\left({1939}{,}{9}{,}{1}{,}{4}{,}{45}{,}{0}{,}{\mathrm{timezone}}{=}{"Europe/Berlin"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (11)
 > $\mathrm{d2}≔\mathrm{Date}\left(1945,9,2,9,'\mathrm{timezone}'="Asia/Tokyo"\right)$
 ${\mathrm{Date}}{}\left({1945}{,}{9}{,}{2}{,}{9}{,}{0}{,}{0}{,}{\mathrm{timezone}}{=}{"Asia/Tokyo"}{,}{\mathrm{coefficient}}{=}{1}\right)$ (12)

The result is in milliseconds, since that is the precision of the UTC clock.

 > $\mathrm{tdiff}≔\mathrm{d2}-\mathrm{d1}$
 ${\mathrm{tdiff}}{≔}{189461700000}{}⟦{\mathrm{ms}}⟧$ (13)

Use the convert command with the units option to convert the result to a more convenient form.

 > $\mathrm{convert}\left(\mathrm{tdiff},'\mathrm{units}','\mathrm{days}'\right)$
 $\frac{{70171}}{{32}}{}⟦{d}⟧$ (14)
 > $\mathrm{convert}\left(\mathrm{tdiff},'\mathrm{units}','\mathrm{years}'\right)$
 ${6.003807364}{}⟦{\mathrm{yr}}⟧$ (15)
 > 

Compatibility

 • The Date command was introduced in Maple 2018.