DateString

DateString[]

gives a string representing the complete current local date and time.

DateString[date]

gives a string corresponding to the given date specification.

DateString[{"elem1","elem2",}]

concatenates the specified elements in the order given.

DateString[date,fmt]

gives elements specified by the date format fmt for the date or time specification date.

Details and Options

  • DateString is typically used to generate human-readable dates in reports and tables or machine-readable dates following international standards and conventions.
  • In DateString[date], the following date and time specifications can be given as date:
  • dateDateObject specification
    {y,m,d,h,m,s}DateList specification
    timeAbsoluteTime specification
    "string"DateString specification
    {"string",fmt}date string formed from the specified format
  • A date string is formed by a sequence of date elements, such as "Year", "Month", "Day", etc. Frequent collections of elements are given special names, such as "DateTimeShort" or "ISOWeekDate", and can be used as elements of a date string.
  • DateString[elem] is equivalent to DateString[{elem}].
  • In DateString[date,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 dateWednesday 26 July 2023
    "DateShort"short dateWed 26 Jul 2023
    "Time"full time11:02:11
    "DateTime"full date and timeWednesday 26 July 2023 11:02:11
    "DateTimeShort"short date and timeWed 26 Jul 2023 11:02:11
    "ISODate"ISO-8601 date2023-07-26
    "ISOWeekDate"ISO week date2023-W30-3
    "ISOOrdinalDate"ISO ordinal date2023-207
    "ISODateTime"ISO date and time2023-07-26T11:02:11
    "ISODateTimeMillisecond"ISO date and time with ms2023-07-26T11:02:11.123
  • Named formats that include locale-based format specifications include:
  • "LocaleDateCompact"date using only numeric elements (e.g. 7/26/23)
    "LocaleDateShort"date using abbreviated day/month (e.g. Jul 26, 2023)
    "LocaleDateLong"date using full day/month (e.g. July 26, 2023)
    "LocaleDateFull"date with day name (e.g. Wednesday, July 26, 2023)
    "LocaleTimeCompact"time excluding seconds (e.g. 11:02 AM)
    "LocaleTimeShort"time with seconds (e.g. 11:02:11 AM)
    "LocaleTimeLong"time with time zone abbreviation (e.g. 11:02:11 AM CST)
    "LocaleTimeFull"time with long time zone (e.g. 11:02:11 AM Central Standard Time)
    "LocaleDateTimeCompact"compact date with time (e.g. 7/26/23,11:02:11 AM)
    "LocaleDateTimeShort"medium date with time (e.g. Jul 26, 2023, 11:02:11 AM)
    "LocaleDateTimeLong"long date with time (e.g. July 26, 2023 at 11:02:11 AM)
    "LocaleDateTimeFull"full date and time (e.g. Wednesday, July 26, 2023 at 11:02:11 AM)
  • 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
    "YearExact"year with fraction2005.26
    "YearFraction"fractional year0.256625
    "ISOYear"ISO-8601 year2005
    "YearSigned"include - for negative years-2005
    "YearUnsigned"year without sign2005
    "YearADBC"include suffix pre-1000940 AD
    "YearCEBCE"include suffix pre-1000940 CE
    "YearRomanNumeral"year in Roman numeralsMMV
    "ADBC"AD or BCAD
    "CEBCE"CE or BCEBCE
  • Elements related to month include the following:
  • "Month"2digit month number08
    "MonthShort"1 or 2digit month number8
    "MonthExact"month including fraction8.26759
    "MonthFraction"fractional part of month0.267586
    "MonthName"month nameAugust
    "MonthNameShort"month name in short formAug
    "MonthNameInitial"first letter of month nameA
    "MonthRomanNumeral"month in Roman numeralsVIII
    "MonthRomanNumeralLowerCase"lowercase Roman numeralsviii
  • Elements related to day of the month include the following:
  • "Day"2digit day of the month09
    "DayShort"1 or 2digit day9
    "DayExact"day including fraction9.29518
    "DayFraction"fractional part of day0.295176
  • 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
    "ISOWeekDayExact"day number with fraction4.29518
    "ISOWeekDayFraction"fractional day number0.295176
  • Elements related to hour include the following:
  • "Hour"
  • 2digit 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
    "HourExact"hour including fraction7.08422
    "HourFraction"fractional part of hour0.0842222
    "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
    "MinuteExact"minute including fraction5.05333
    "MinuteFraction"fractional part of minute0.0533333
  • Elements related to second include the following:
  • "Second"2digit seconds03
    "SecondShort"1 or 2digit seconds3
    "SecondExact"seconds including fractions03.199
    "SecondFraction"fractional part of second0.2
    "Millisecond"3digit milliseconds019
    "MillisecondShort"1, 2, or 3digit milliseconds19
    "MillisecondExact"millisecond with fraction019.99
    "MillisecondFraction"fractional part of millisecond0.999809
  • Elements larger than a year include the following:
  • "Millennium"beginning with year X000-3000
    "MillenniumUnsigned"unsigned millennium3000
    "MillenniumBeginning01"beginning with year X0012001
    "Century"beginning with year XX00-2100
    "CenturyUnsigned"unsigned century2100
    "CenturyBeginning01"beginning with year XX012001
    "Decade"10 year period-2010
    "DecadeUnsigned"unsigned decade2010
  • 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"2digit week number 02
    "WeekShort"1- or 2digit week number 2
    "WeekExact"week including fraction2.44048
    "WeekFraction"fractional week number0.440478
  • Additional ISO-8601 date elements include the following:
  • "ISOYearDay"3digit day of the year094
    "ISOYearDayShort"1, 2 or 3digit day of year94
    "ISOYearDayExact"year day including fraction94.295
    "ISOYearDayFraction"fractional part of year day0.295176
  • 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 concatenated literally in the output string.
  • DateString[] by default gives its output in the form specified by $DateStringFormat.
  • In the cloud, $DateStringFormat is set according to the locale information given by $GeoLocationCountry.
  • With a typical value for $DateStringFormat, DateString[{y,m,d,h,m,s}] will truncate fractional seconds.
  • Shorter lists can be used in 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 the form DateString[{"string",{"e1","e2",},], the "ei" can be "Year", "YearShort", "Quarter", "Month", "MonthName", "Day", "DayName", "Hour", "Hour12", "AMPM", "Minute", or "Second".
  • DateString[{"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 DateString[{"string",{"e1","e2",},], the "ei" are extracted from "string" in the order given and can be separated by any non-alphanumeric characters. »
  • DateString[{"string",{"e1","sep12","e2","sep23",},] extracts elements using the explicit separators specified. »
  • For "*Exact" elements (such as "SecondExact" and "MonthExact"), the integer part of the returned value will match the value given by the normal element (i.e. "Second" and "Month").
  • DateString[date] uses the DateFormat value of the specified DateObject to determine the elements included in the resulting string.
  • In DateString[spec,elems], the time and date corresponding to spec are by default assumed to be in the time zone specified by $TimeZone, unless spec explicitly specifies another time zone.
  • DateString[spec,elems,TimeZone->z] gives output converted to time zone z.
  • DateString[] uses whatever date and time have been set on your computer system. It performs no corrections for time zones, daylight saving time, etc.
  • DateString[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 $TimeZone. »

Examples

open allclose all

Basic Examples  (5)

Find the current date:

The current date in a specific format:

Another date in a specific format:

DateString supports a number of ISO-8601 date formats:

Get the current date in Japanese:

Scope  (13)

Find the day of the week corresponding to a date:

Date lists are converted to standard normalized form:

Strings are automatically interpreted when possible:

Both DateObject and TimeObject expressions include default DateFormat values:

Separators for input strings are assumed if not specified:

Give explicit separators for an input date string:

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

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

Convert an absolute time to a date string:

Get a date string in French:

Generate a date string based on your system's language locale:

Specify a language and locale format:

Specify which elements to include and in what language at the same time:

Options  (1)

TimeZone  (1)

Find the current date in Greenwich, United Kingdom:

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

Applications  (1)

Make a dynamically updating clock:

Properties & Relations  (6)

DateObject represents a given date:

AbsoluteTime represents dates as seconds since the beginning of 1900:

DateList represents dates as lists of date elements:

DateString represents dates as strings:

Use $DateStringFormat to define the output formatting:

DateString gives results that match a DatePattern:

Use DateListPlot to plot data with date string coordinates:

Use DatePlus to add time units to a date string:

Use DateDifference to find the number of time units between dates:

Use Order and DateList to determine the order of dates:

Possible Issues  (3)

Explicit elements may be needed to interpret ambiguous strings:

For numeric TimeZone values, the elements "TimeZoneName" and "TimeZoneNameShort" are returned as GMT offsets:

When using a named TimeZone, an appropriate "TimeZoneName" will be returned:

The element "WeekExact" uses the same integer part as "Week" and thus will never return a value smaller than 1:

The same is true for all zero-indexed elements:

Wolfram Research (2007), DateString, Wolfram Language function, https://reference.wolfram.com/language/ref/DateString.html (updated 2024).

Text

Wolfram Research (2007), DateString, Wolfram Language function, https://reference.wolfram.com/language/ref/DateString.html (updated 2024).

CMS

Wolfram Language. 2007. "DateString." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/DateString.html.

APA

Wolfram Language. (2007). DateString. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/DateString.html

BibTeX

@misc{reference.wolfram_2024_datestring, author="Wolfram Research", title="{DateString}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/DateString.html}", note=[Accessed: 17-November-2024 ]}

BibLaTeX

@online{reference.wolfram_2024_datestring, organization={Wolfram Research}, title={DateString}, year={2024}, url={https://reference.wolfram.com/language/ref/DateString.html}, note=[Accessed: 17-November-2024 ]}