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:
-
date DateObject specification {y,m,d,h,m,s} DateList specification time AbsoluteTime 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:
-
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 Wednesday 26 July 2023 "DateShort" short date Wed 26 Jul 2023 "Time" full time 11:02:11 "DateTime" full date and time Wednesday 26 July 2023 11:02:11 "DateTimeShort" short date and time Wed 26 Jul 2023 11:02:11 "ISODate" ISO-8601 date 2023-07-26 "ISOWeekDate" ISO week date 2023-W30-3 "ISOOrdinalDate" ISO ordinal date 2023-207 "ISODateTime" ISO date and time 2023-07-26T11:02:11 "ISODateTimeMillisecond" ISO date and time with ms 2023-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 year 2005 "YearShort" 2-digit year 05 "YearExact" year with fraction 2005.26 "YearFraction" fractional year 0.256625 "ISOYear" ISO-8601 year 2005 "YearSigned" include - for negative years -2005 "YearUnsigned" year without sign 2005 "YearADBC" include suffix pre-1000 940 AD "YearCEBCE" include suffix pre-1000 940 CE "YearRomanNumeral" year in Roman numerals MMV "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 "MonthExact" month including fraction 8.26759 "MonthFraction" fractional part of month 0.267586 "MonthName" month name August "MonthNameShort" month name in short form Aug "MonthNameInitial" first letter of month name A "MonthRomanNumeral" month in Roman numerals VIII "MonthRomanNumeralLowerCase" lowercase Roman numerals viii - 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 "DayExact" day including fraction 9.29518 "DayFraction" fractional part of day 0.295176 - 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 "ISOWeekDayExact" day number with fraction 4.29518 "ISOWeekDayFraction" fractional day number 0.295176 - 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 "HourExact" hour including fraction 7.08422 "HourFraction" fractional part of hour 0.0842222 "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 "MinuteExact" minute including fraction 5.05333 "MinuteFraction" fractional part of minute 0.0533333 - 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 larger than a year include the following:
-
"Millennium" beginning with year X000 -3000 "MillenniumUnsigned" unsigned millennium 3000 "MillenniumBeginning01" beginning with year X001 2001 "Century" beginning with year XX00 -2100 "CenturyUnsigned" unsigned century 2100 "CenturyBeginning01" beginning with year XX01 2001 "Decade" 10 year period -2010 "DecadeUnsigned" unsigned decade 2010 - 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 "WeekExact" week including fraction 2.44048 "WeekFraction" fractional week number 0.440478 - 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 "ISOYearDayExact" year day including fraction 94.295 "ISOYearDayFraction" fractional part of year day 0.295176 - 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 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 allBasic Examples (5)
The current date in a specific format:
Another date in a specific format:
DateString supports a number of ISO-8601 date formats:
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:
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)
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:
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:
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