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:
  • Automaticdetermine date format automatically
    "format"named date format (e.g. "ISODateTime")
    {elem1,elem2,}ordered elements (e.g. "Year", "Day", )
    assocAssociation of date format parameters
    localelocale 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"Automaticdate string elements to include
    "Language"$Languagelanguage for text elements
    "WritingScript"Automaticwriting script for text elements
    "Delimiters"Automaticdelimiters 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 dateThursday 4 April 2019
    "DateShort"short dateThu 4 Apr 2019
    "Time"full time15:57:49
    "DateTime"full date and timeThursday 4 April 2019 15:57:57
    "DateTimeShort"short date and timeThu 4 Apr 2019 15:58:08
    "ISODate"ISO-8601 date2019-04-04
    "ISOWeekDate"ISO week date2019-W14-4
    "ISOOrdinalDate"ISO ordinal date2019-094
    "ISODateTime"ISO date and time2019-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 year2005
    "YearShort"2-digit year05
    "ISOYear"ISO-8601 year2005
    "YearUnsigned"year without sign2005
    "ADBC"AD or BCAD
    "CEBCE"CE or BCEBCE
  • Elements related to month include the following:
  • "Month"2-digit month number08
    "MonthShort"1- or 2-digit month number8
    "MonthName"month nameAugust
    "MonthNameShort"month name in short formAug
    "MonthNameInitial"first letter of month nameA
  • Elements related to day of the month include the following:
  • "Day"2-digit day of the month09
    "DayShort"1- or 2-digit day9
  • Elements related to day of the week include the following:
  • "DayName"day of the weekWednesday
    "DayNameShort"short day of the weekWed
    "DayNameInitial"first letter of day nameW
    "ISOWeekDay"ISO-8601 day number4
  • Elements related to hour include the following:
  • "Hour"
  • 2-digit hour
  • 19
    "Hour12"2-digit 12-hour clock07
    "Hour24"2-digit 24-hour clock19
    "HourShort"1- or 2-digit hour19
    "Hour12Short"1- or 2-digit 12-hour clock7
    "Hour24Short"1- or 2-digit 24-hour clock19
    "AMPM"AM or PMPM
    "AMPMLowerCase"am or pmpm
  • Elements related to minute include the following:
  • "Minute"2-digit minute05
    "MinuteShort"1- or 2-digit minute5
  • Elements related to second include the following:
  • "Second"2-digit seconds03
    "SecondShort"1- or 2-digit seconds3
    "SecondExact"seconds including fractions03.199
    "SecondFraction"fractional part of second0.2
    "Millisecond"3-digit milliseconds019
    "MillisecondShort"1-, 2-, or 3-digit milliseconds19
    "MillisecondExact"millisecond with fraction019.99
    "MillisecondFraction"fractional part of millisecond0.999809
  • Elements related to multiple date elements include the following:
  • "Quarter"quarter number1
    "QuarterName"quarter of yearQuarter 1
    "QuarterNameShort"quarter of year in short formQ1
    "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 year094
    "ISOYearDayShort"1-, 2- or 3-digit day of year94
  • Elements related to time zone include the following:
  • "TimeZoneGMTRelative"GMT offsetGMT-04:00
    "ISOTimeZone"ISO-8601 GMT offset-04:00
    "TimeZoneName"time zone nameEastern Standard Time
    "TimeZoneNameShort"short time zone nameEST
  • Any other string given in the list of elements is assumed to appear literally in the date string.
  • Possible options include:
  • CalendarType Automaticoutput calendar system
    DateFormat Automaticformat used to display date
    DateGranularity Automaticoutput calendar granularity
    TimeSystemAutomatictime system being used
    TimeZone Automaticoutput 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 all

Basic 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)

Generate Japanese calendar date from a date string input:

Date string inputs are implicitly Gregorian calendar dates, so conversion will be done automatically:

DateFormat  (2)

By default, generated dates will use the default DateObject date format:

Specifying a DateFormat will ensure the resulting object typesets accordingly:

Specify your own date format:

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:

Possible Issues  (1)

In some cases, date string inputs may be ambiguous:

In such cases, a locale may be used to disambiguate the expected order of elements:

Wolfram Research (2021), FromDateString, Wolfram Language function, https://reference.wolfram.com/language/ref/FromDateString.html (updated 2023).

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

BibTeX

@misc{reference.wolfram_2024_fromdatestring, author="Wolfram Research", title="{FromDateString}", year="2023", howpublished="\url{https://reference.wolfram.com/language/ref/FromDateString.html}", note=[Accessed: 21-December-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_fromdatestring, organization={Wolfram Research}, title={FromDateString}, year={2023}, url={https://reference.wolfram.com/language/ref/FromDateString.html}, note=[Accessed: 21-December-2024 ]}