DateObject

DateObject[]

gives the current local date.

DateObject[{y,m,d,h,m,s}]

gives a date object of standard normalized form.

DateObject["string"]

converts a date string to a date object.

DateObject[{"string",{"e1","e2", }}]

gives the date object obtained by extracting elements "ei" from "string".

DateObject[rdate,gran]

gives the date object of calendar granularity gran that includes the reference date rdate.

Details and Options

  • DateObject[] uses whatever date and time have been set on your computer system by default.
  • Values of m, d, h, m, s outside their normal ranges are appropriately reduced. Noninteger values of d, h, m, and s can also be used.
  • In the form DateObject[{"string",{"e1","e2",}}], the "ei" can be "Year", "YearShort", "Quarter", "Month", "MonthName", "Day", "DayName", "Hour", "Hour12", "AMPM", "Minute", "Second", or "Millisecond".
  • DateObject[{"string",{"e1","e2",}}] uses the "ei" to fill in elements of {y,m,d,h,m,s}. Those not filled in are taken to have default values {yc,1,1,0,0,0}, where yc is the current year.
  • In DateObject[{"string",{"e1","e2",}}], the "ei" are extracted from "string" in the order given, and can be separated by any non-alphanumeric characters.
  • DateObject[{"string",{"e1","sep12","e2","sep23",}}] extracts elements using the explicit separators specified.
  • DateObject[time] gives a date object corresponding to an AbsoluteTime specification.
  • For an image with Exif date time information, DateObject[image] returns that information as a standard DateObject expression.
  • DateObject[rdate,gran] represents a discrete calendar element of granularity gran starting on or including the reference date rdate. For example, DateObject[{2017,1,16},"Week"] represents the week including Monday, January 16, 2017.
  • In DateObject[rdate,gran], the calendar granularity gran can be any of the following:
  • "Millennium"1000-year period beginning with year XX00
    "MillenniumBeginning01"1000-year period beginning with year XX01
    "Century"100-year period beginning with year XX00
    "CenturyBeginning01"100-year period beginning with year XX01
    "Decade"10-year period including the date
    "Year"year including the date
    "Quarter"3-month quarter including the date
    "Month"month including the date
    "Week"week beginning Monday including the date
    "WeekBeginningSunday"week beginning Sunday including the date
    "Day"day including the date
    "Hour"hour including the date
    "Minute"minute including the date
    "Second"second including the date
    "Instant"the exact instant specified
  • DateObject[rdate,"MidpointInstant"] can be used to construct a DateObject with granularity "Instant" with a reference date at the mid-point of rdate.
  • DateObject[list] is taken to represent a date with granularity as follows:
  • DateObject[{y}]"Year"
    DateObject[{y,m}]"Month"
    DateObject[{y,m,d}]"Day"
    DateObject[{y,m,d,h}]"Hour"
    DateObject[{y,m,d,h,m}]"Minute"
    DateObject[{y,m,d,h,m,s}]"Instant"
    DateObject[t]"Instant"
  • DateObject["string"] is taken to represent a date with granularity inferred from the information given in the string.
  • The following options can be given:
  • CalendarTypeAutomaticcalendar system being used
    DateFormatAutomaticformat used to display date
    TimeZoneAutomatictime zone being used
  • Possible CalendarType specifications are: Automatic, "Gregorian", "Julian", "Jewish", and "Islamic".
  • The default value of CalendarType is Automatic, which uses the proleptic Gregorian calendar in which there is no year 0. Years prior to the Common Era are negative, and those after are positive.
  • TimeZone specifications should be a numerical offset from GMT, a time zone string, or a geo entity location.
  • With a typical value for $DateStringFormat, the display of DateObject[{y,m,d,h,m,s}] will truncate fractional seconds.
  • DateObject allows addition and subtraction of time quantities.
  • Subtracting two DateObject expressions yields a time quantity.
  • Functions such as Sort, Greater, Max, etc. work with DateObject.

Examples

open allclose all

Basic Examples  (6)

Find the current date:

In[1]:=
Click for copyable input
Out[1]=

Date object expression representing the year 2015:

In[1]:=
Click for copyable input
Out[1]=

Date object representing the week including Thursday, August 4, 2016:

In[1]:=
Click for copyable input
Out[1]=

Convert an absolute time to a date object:

In[1]:=
Click for copyable input
Out[1]=

Represent a specific year and month:

In[1]:=
Click for copyable input
Out[1]=

Or represent just a year:

In[2]:=
Click for copyable input
Out[2]=

Add 1000 weeks to a date:

In[1]:=
Click for copyable input
Out[1]=

Subtract two dates to get a time quantity:

In[2]:=
Click for copyable input
Out[2]=

Scope  (6)

Options  (5)

Properties & Relations  (8)

See Also

TimeObject  Now  DateValue  TimeZoneConvert  CalendarConvert  DateString  DateList  AbsoluteTime  UnixTime  FromUnixTime  JulianDate  FromJulianDate  TimeSeries  EventSeries

Introduced in 2014
(10.0)
| Updated in 2017
(11.1)