({{, (RefLink[DateString, paclet:ref/DateString])[] 
gives a string representing the complete current local date and time. }, {, (RefLink[DateString, paclet:ref/DateString])["elem"] 
gives the specified element or format for date and time.}, {, (RefLink[DateString, paclet:ref/DateString])[{"(Subscript[elem, 1])","(Subscript[elem, 2])",…}] 
concatenates the specified elements in the order given.}, {, (RefLink[DateString, paclet:ref/DateString])[{y,m,d,h,m,s}] 
gives a string corresponding to a (RefLink[DateList, paclet:ref/DateList]) specification.}, {, (RefLink[DateString, paclet:ref/DateString])[time] 
gives a string corresponding to an (RefLink[AbsoluteTime, paclet:ref/AbsoluteTime]) specification.}, {, (RefLink[DateString, paclet:ref/DateString])[date]
gives a string corresponding to a (RefLink[DateObject, paclet:ref/DateObject]) specification.}, {, (RefLink[DateString, paclet:ref/DateString])[spec,elems] 
gives elements elems of the date or time specification spec.}})

OpenersNotesSection(Spacer1)Details and Options

(RefLink[DateString, paclet:ref/DateString])[] by default gives its output in the form specified by (RefLink[$DateStringFormat, paclet:ref/$DateStringFormat]).

The following date format specifications can be given as elements:

Elements related to year include the following:

Elements related to month include the following:

Elements related to day of the month include the following:

Elements related to day of the week include the following:

Elements related to hour include the following:

Elements related to minute include the following:

Elements related to second include the following:

Elements larger than a year include the following:

Elements related to multiple date elements include the following:

Additional ISO-8601 date elements include the following:

Elements related to time zone include the following:

Any other string given in the list of elements is concatenated literally in the output string.

With a typical value for (RefLink[$DateStringFormat, paclet:ref/$DateStringFormat]), (RefLink[DateString, paclet:ref/DateString])[{y,m,d,h,m,s}] will truncate fractional seconds.

Shorter lists can be used in (RefLink[DateString, paclet:ref/DateString])[{y,m,…}]: {y} is equivalent to {y,1,1,0,0,0}, {y,m} to {y,m,1,0,0,0}, etc.

Values of m, d, h, m, s outside their normal ranges are appropriately reduced. Noninteger values of d, h, m, s can also be used. »

In (RefLink[DateString, paclet:ref/DateString])[spec,elems], the following date and time specifications can be given as spec:

In the form (RefLink[DateString, paclet:ref/DateString])[{"string",{"(Subscript[e, 1])","(Subscript[e, 2])",…},…], the "(Subscript[e, i])" can be "Year", "YearShort", "Quarter", "Month", "MonthName", "Day", "DayName", "Hour", "Hour12", "AMPM", "Minute", or "Second".

(RefLink[DateString, paclet:ref/DateString])[{"string",{"(Subscript[e, 1])","(Subscript[e, 2])",…},…] uses the "(Subscript[e, i])" to fill in elements of {y,m,d,h,m,s}. Those not filled in are taken to have default values {(Subscript[y, c]),1,1,0,0,0}, where (Subscript[y, c]) is the current year. »

In (RefLink[DateString, paclet:ref/DateString])[{"string",{"(Subscript[e, 1])","(Subscript[e, 2])",…},…], the "(Subscript[e, i])" are extracted from "string" in the order given, and can be separated by any non-alphanumeric characters. »

(RefLink[DateString, paclet:ref/DateString])[{"string",{"(Subscript[e, 1])","(Subscript[sep, 12])","(Subscript[e, 2])","(Subscript[sep, 23])",…},…] extracts elements using the explicit separators specified. »

(RefLink[DateString, paclet:ref/DateString])[date] uses the (RefLink[DateFormat, paclet:ref/DateFormat]) value of the specified (RefLink[DateObject, paclet:ref/DateObject]) to determine the elements included in the resulting string.

In (RefLink[DateString, paclet:ref/DateString])[spec,elems], the time and date corresponding to spec are by default assumed to be in the time zone specified by (RefLink[$TimeZone, paclet:ref/$TimeZone]), unless spec explicitly specifies another time zone.

(RefLink[DateString, paclet:ref/DateString])[spec,elems,(RefLink[TimeZone, paclet:ref/TimeZone])->z] gives output converted to time zone z.

(RefLink[DateString, paclet:ref/DateString])[] uses whatever date and time have been set on your computer system. It performs no corrections for time zones, daylight saving time, etc.

(RefLink[DateString, paclet:ref/DateString])[(RefLink[TimeZone, paclet:ref/TimeZone]) -> z] gives the date and time inferred for time zone z by assuming that your computer is set for the time zone specified by (RefLink[$TimeZone, paclet:ref/$TimeZone]). »

OpenersPrimaryExamplesSection(Spacer1)Examples  (23)

OpenersExampleSection0(Spacer1)Basic Examples  (4)

Find the current date:

DateString[]

The current date in a specific format:

DateString[{"DayName", "  ","Month","/","YearShort"}]

Another date in a specific format:

DateString[(DateObject["Day: ""Fri 19 Dec 2014", DateObject[{2014,12,19},"Day","Gregorian",-6.`]]),{"DayName", "  ","Month","/","YearShort"}]

(RefLink[DateString, paclet:ref/DateString]) supports a number of ISO-8601 date formats:

DateString["ISODate"]

DateString["ISODateTime"]

DateString["ISOWeekDate"]

DateString["ISOOrdinalDate"]

OpenersExampleSection1(Spacer1)Scope  (9)

Find the day of the week corresponding to a date:

DateString[(DateObject["Day: ""Sat 29 Aug 1959", DateObject[{1959,8,29},"Day","Gregorian",-6.`]]),"DayName"]

Date lists are converted to standard normalized form:

DateString[{2006,2,31}]

DateString[{2006,3,3}]

Strings are automatically interpreted when possible:

DateString["2006-12-1","MonthName"]

DateString["10 March 2006","Year"]

Both (RefLink[DateObject, paclet:ref/DateObject]) and (RefLink[TimeObject, paclet:ref/TimeObject]) expressions include default (RefLink[DateFormat, paclet:ref/DateFormat]) values:

DateString[DateObject[{2011,4,8}]]

DateString[TimeObject[]]

Separators for input strings are assumed if not specified:

DateString[{"12/26/1980",{"Month","Day","Year"}}]

Give explicit separators for an input date string:

DateString[{"12/26/1980",{"Month","/","Day","/","Year"}}]

Day, hour, minute, and second values can be nonintegers:

DateString[{2007,3,15.5}]

DateString[{2007,3,15,12.3}]

The current year is used if not specified in a string:

DateString[{"2/15",{"Month","Day"}}]

Convert an absolute time to a date string:

DateString[3155673600]

OpenersExampleSection2(Spacer1)Options  (1)

OpenersExampleSubsection0(Spacer1)TimeZone  (1)

Find the current date in Greenwich, United Kingdom:

DateString[TimeZone->0]

Get a date string for a specific date using a time zone string:

DateString[(DateObject["Thu 30 Jul 2015 10:28:10""EST", DateObject[{2015,7,30,10,28,10.59228`},"Instant","Gregorian","America/New_York"]]), TimeZone->"Asia/Tokyo"]

OpenersExampleSection3(Spacer1)Applications  (1)

Make a dynamically updating clock:

Dynamic[Refresh[DateString[],UpdateInterval->1]]

OpenersExampleSection4(Spacer1)Properties & Relations  (6)

(RefLink[DateObject, paclet:ref/DateObject]) represents a given date:

DateObject[{2007,1,1}]

(RefLink[AbsoluteTime, paclet:ref/AbsoluteTime]) represents dates as seconds since the beginning of 1900:

AbsoluteTime[%]

(RefLink[DateList, paclet:ref/DateList]) represents dates as lists of date elements:

DateList[%]

(RefLink[DateString, paclet:ref/DateString]) represents dates as strings:

DateString[%]

Use (RefLink[$DateStringFormat, paclet:ref/$DateStringFormat]) to define the output formatting:

Block[{$DateStringFormat={"Month","/","Day","/","Year"}},
DateString[]]

(RefLink[DateString, paclet:ref/DateString]) gives results that match a (RefLink[DatePattern, paclet:ref/DatePattern]):

DateString[{"Hour",":","Minute"}]

StringMatchQ[%,DatePattern[{"Hour",":","Minute"}]]

Use (RefLink[DateListPlot, paclet:ref/DateListPlot]) to plot data with date string x coordinates:

DateListPlot[{{"Jan 1",2},{"Feb 1",4},{"Mar 1",6},{"Apr 1",8}}]

Use (RefLink[DatePlus, paclet:ref/DatePlus]) to add time units to a date string:

DatePlus["January 1, 2007",{3,"Day"}]

Use (RefLink[DateDifference, paclet:ref/DateDifference]) to find the number of time units between dates:

DateDifference["Feb 1, 2007","May 1, 2007","Day"]

Use (RefLink[Order, paclet:ref/Order]) and (RefLink[DateList, paclet:ref/DateList]) to determine the order of dates:

Order[DateList["Jan 1, 2007"],DateList["May 1, 2007"]]

Order[DateList["May 1, 2007"],DateList["Jan 1, 2007"]]

OpenersExampleSection5(Spacer1)Possible Issues  (2)

Explicit elements may be needed to interpret ambiguous strings:

DateString["05/10/1","MonthName"]

DateString[{"05/10/1",{"YearShort","Day","Month"}},"MonthName"]

For numeric (RefLink[TimeZone, paclet:ref/TimeZone]) values, the elements "TimeZoneName" and "TimeZoneNameShort" are returned as GMT offsets:

DateString[DateList[],"TimeZoneName"]

When using a named (RefLink[TimeZone, paclet:ref/TimeZone]), an appropriate "TimeZoneName" will be returned:

Block[{$TimeZone = "America/Chicago"},DateString[DateList[],"TimeZoneName"]
]

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[DateList, paclet:ref/DateList])  ▪  (RefLink[DateObject, paclet:ref/DateObject])  ▪  (RefLink[DatePlus, paclet:ref/DatePlus])  ▪  (RefLink[DateDifference, paclet:ref/DateDifference])  ▪  (RefLink[AbsoluteTime, paclet:ref/AbsoluteTime])  ▪  (RefLink[$TimeZone, paclet:ref/$TimeZone])  ▪  (RefLink[SessionTime, paclet:ref/SessionTime])  ▪  (RefLink[TimeUsed, paclet:ref/TimeUsed])  ▪  (RefLink[FileDate, paclet:ref/FileDate])  ▪  (RefLink[$CreationDate, paclet:ref/$CreationDate])  ▪  (RefLink[ToUpperCase, paclet:ref/ToUpperCase])  ▪  (RefLink[ToLowerCase, paclet:ref/ToLowerCase])  ▪  (RefLink[DateListPlot, paclet:ref/DateListPlot])  ▪  (RefLink[$DateStringFormat, paclet:ref/$DateStringFormat])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Date & Time, paclet:guide/DateAndTime])}, {▪(RefLinkPlain[Converting between Expressions & Strings, paclet:guide/ConvertingBetweenExpressionsAndStrings])}, {▪(RefLinkPlain[Locale & Internationalization, paclet:guide/LocaleAndInternationalization])}, {▪(RefLinkPlain[Cloud Execution Metadata, paclet:guide/CloudExecutionMetadata])}, {▪(RefLinkPlain[Text Generation, paclet:guide/TextConstruction])}, {▪(RefLinkPlain[Wolfram System Session Information, paclet:guide/WolframSystemSessionInformation])}})}})

({{(Spacer1), ({{(Spacer1)Related Links}, {(WebLink[DocumentationFooterIconsRelatedLinks-EIWL.png(Spacer1)An Elementary Introduction to the Wolfram Language, https://www.wolfram.com/language/elementary-introduction/19-dates-and-times.html])(WebLink[: Dates and Times, https://www.wolfram.com/language/elementary-introduction/19-dates-and-times.html])}})}})