FromDateString
FromDateString["string"]
gives a date object corresponding to the date represented by "string".
FromDateString["string",{"e1","e2",…}]
gives the date object obtained by extracting elements "ei" from "string".
FromDateString["string",fmt]
gives the date object obtained using the date format fmt.
Details and Options
- FromDateString parses any string representing a date into its Wolfram Language canonical DateObject form, taking into account locale and time zone information.
- FromDateString accepts arrays of date strings.
- In FromDateString["string",fmt], the format specification fmt typically includes:
-
Automatic determine date format automatically "format" named date format (e.g. "ISODateTime") {elem1,elem2,…} ordered elements (e.g. "Year", "Day", …) assoc Association of date format parameters locale locale specification (e.g. "en_US") - locale uses the default date formatting information specified by the given locale, including element ordering, language, writing script and delimiters. Locale specifications may be given using locale strings such as "en_US", "LanguageLocale" entities or "Language" entities.
- The following parameters may be specified in assoc specifications:
-
"Elements" Automatic date string elements to include "Language" $Language language for text elements "WritingScript" Automatic writing script for text elements "Delimiters" Automatic delimiters to use between date elements - "Language"lang specifications may be given using a language string (i.e. "Spanish"), ISO-639 language code (i.e. "es"), a "Language" entity or "LanguageLocale" entity.
- "WritingScript"script specifications may be given using a writing script string (i.e. "Latin"), ISO-15924 writing script code (i.e. "Latn") or a "WritingScript" entity.
- For <"Delimiters"delims >, the delimiters will be inserted in the list of elements following the behavior of Riffle.
- Named format specifications include:
-
"Date" full date Thursday 4 April 2019 "DateShort" short date Thu 4 Apr 2019 "Time" full time 15:57:49 "DateTime" full date and time Thursday 4 April 2019 15:57:57 "DateTimeShort" short date and time Thu 4 Apr 2019 15:58:08 "ISODate" ISO-8601 date 2019-04-04 "ISOWeekDate" ISO week date 2019-W14-4 "ISOOrdinalDate" ISO ordinal date 2019-094 "ISODateTime" ISO date and time 2019-04-04T15:58:57 - Named formats that include locale-based format specifications include:
-
"LocaleDateCompact" date using only numeric elements (e.g. 1/12/21) "LocaleDateShort" date using abbreviated day/month (e.g. Jan. 12, 2021) "LocaleDateLong" date using full day/month (e.g. January 12, 2021) "LocaleDateFull" date with day name (e.g. Tuesday, January 12, 2021) "LocaleTimeCompact" time excluding seconds (e.g. 2:07 PM) "LocaleTimeShort" time with seconds (e.g. 2:07:23 PM) "LocaleTimeLong" time with time zone abbreviation (e.g. 2:07:23 PM CST) "LocaleTimeFull" time with long time zone (e.g. 2:07:23 PM Central Standard Time) "LocaleDateTimeCompact" compact date with time (e.g. 1/12/21, 2:07:23 PM) "LocaleDateTimeShort" medium date with time (e.g. Jan 12, 2021, 2:07:23 PM) "LocaleDateTimeLong" long date with time (e.g. January 12, 2021 at 2:07:23 PM) "LocaleDateTimeFull" full date and time (e.g. Tuesday, January 12, 2021 at 2:07:23 PM) - The exact elements included and their order are determined by the locale used alongside these named formats.
- Elements related to year include the following:
-
"Year" full year 2005 "YearShort" 2-digit year 05 "ISOYear" ISO-8601 year 2005 "YearUnsigned" year without sign 2005 "ADBC" AD or BC AD "CEBCE" CE or BCE BCE - Elements related to month include the following:
-
"Month" 2-digit month number 08 "MonthShort" 1- or 2-digit month number 8 "MonthName" month name August "MonthNameShort" month name in short form Aug "MonthNameInitial" first letter of month name A - Elements related to day of the month include the following:
-
"Day" 2-digit day of the month 09 "DayShort" 1- or 2-digit day 9 - Elements related to day of the week include the following:
-
"DayName" day of the week Wednesday "DayNameShort" short day of the week Wed "DayNameInitial" first letter of day name W "ISOWeekDay" ISO-8601 day number 4 - Elements related to hour include the following:
-
"Hour" - 2-digit hour
19 "Hour12" 2-digit 12-hour clock 07 "Hour24" 2-digit 24-hour clock 19 "HourShort" 1- or 2-digit hour 19 "Hour12Short" 1- or 2-digit 12-hour clock 7 "Hour24Short" 1- or 2-digit 24-hour clock 19 "AMPM" AM or PM PM "AMPMLowerCase" am or pm pm - Elements related to minute include the following:
-
"Minute" 2-digit minute 05 "MinuteShort" 1- or 2-digit minute 5 - Elements related to second include the following:
-
"Second" 2-digit seconds 03 "SecondShort" 1- or 2-digit seconds 3 "SecondExact" seconds including fractions 03.199 "SecondFraction" fractional part of second 0.2 "Millisecond" 3-digit milliseconds 019 "MillisecondShort" 1-, 2-, or 3-digit milliseconds 19 "MillisecondExact" millisecond with fraction 019.99 "MillisecondFraction" fractional part of millisecond 0.999809 - Elements related to multiple date elements include the following:
-
"Quarter" quarter number 1 "QuarterName" quarter of year Quarter 1 "QuarterNameShort" quarter of year in short form Q1 "Week" 2-digit week number 02 "WeekShort" 1- or 2-digit week number 2 - Additional ISO-8601 date elements include the following:
-
"ISOYearDay" 3-digit day of the year 094 "ISOYearDayShort" 1-, 2- or 3-digit day of year 94 - Elements related to time zone include the following:
-
"TimeZoneGMTRelative" GMT offset GMT-04:00 "ISOTimeZone" ISO-8601 GMT offset -04:00 "TimeZoneName" time zone name Eastern Standard Time "TimeZoneNameShort" short time zone name EST - Any other string given in the list of elements is assumed to appear literally in the date string.
- Possible options include:
-
CalendarType Automatic output calendar system DateFormat Automatic format used to display date DateGranularity Automatic output calendar granularity TimeSystem Automatic time system being used TimeZone Automatic output time zone - Possible CalendarType specifications include Automatic, "Gregorian", "Julian" and all other calendars in CalendarData["DateCalendar"].
- TimeZone specifications should be a numerical offset from GMT, a time zone string or entity, None or a geo entity location.
- DateFormat may be used to specify the output format of the DateObject returned by FromDateString.
- "string" inputs are always assumed to be in the "Gregorian" calendar system.
Examples
open allclose allBasic Examples (4)
Get a date object from a date string input:
Parse a date string using a specific date format:
Date format specifications can include elements, language, writing script and delimiters:
A locale can be specified as the date format, which provides the elements and their ordering, as well as the language and script:
Scope (6)
When no reference format is given, FromDateString will attempt to determine the date format automatically:
FromDateString[date] is equivalent to FromDateString[date,Automatic]:
A format specification may be a named date format or a single date element:
An explicit list of date format elements may also be given:
The language used by text elements in the date format may be specified using a "Language" entity:
Language specifications may also be given using a "LanguageLocale" entity, ISO-639 language code or language string:
Some languages have multiple frequently used writing scripts, which can be differentiated with a "WritingScript" entity:
Writing script specifications may also be given using ISO-15924 writing script codes or writing script strings, or as part of a language specification using a "LanguageLocale" entity:
When a single delimiter is given, it will be inserted between each date format element:
When a list of delimiters is given, they will be interspersed between the date format elements:
A locale may also be used as a format specification, which will use the appropriate elements, ordering, language, writing script and delimiters for the locale:
Locale specifications may also be given as a "Language" entity or "LanguageLocale" entity:
Options (7)
CalendarType (2)
DateFormat (2)
By default, generated dates will use the default DateObject date format:
Specifying a DateFormat will ensure the resulting object typesets accordingly:
DateGranularity (1)
By default, FromDateString determines the granularity of the output based on the input string:
Use DateGranularity"Instant" to generate a date with a specific granularity:
TimeZone (2)
FromDateString will attempt to parse time zone information when available, returning in the parsed time zone by default:
If not time zone information is present, the string will be assumed to be in $TimeZone:
TimeZonezone can be used to explicitly specify a desired output time zone:
A time zone specification of None will produce an object without an embedded time zone:
Text
Wolfram Research (2021), FromDateString, Wolfram Language function, https://reference.wolfram.com/language/ref/FromDateString.html (updated 2023).
CMS
Wolfram Language. 2021. "FromDateString." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2023. https://reference.wolfram.com/language/ref/FromDateString.html.
APA
Wolfram Language. (2021). FromDateString. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FromDateString.html