ParseDate


Release:

…  • 4.6 •  5.0 •  5.1 •  5.2 •  5.3 •  5.4 •  6.0 •  6.1 •  6.2 •  6.3 •  6.4 •  6.5 •   •  6.6 •  7.0 •  7.1 •  7.2

ParseDate(date, badVal, dateTemplate, timeZone)

Parses a textual date «date» into a date time value, with a numeric value equal to the number of days elapsed since Analytica's date origin. When the "Use Excel date origin" preference is not set, the origin is 1 Jan 1904, and when set it is 1 Jan 1900.

An optional second parameter, «badVal», specifies the value returned when «date» does not parse as a date-time, or is not text. The default when this parameter is omitted is to return Null. A useful usage is to repeat the first parameter as the second parameter, as in ParseDate(x, x), which then parses the date cells and leaves all other cells with the values already there.

A date like "09/10/11" would usually be interpreted as 10-Sep-2011 in the United States, as 9-Nov-2011 in many European and South American countries, and as 11-Oct-2009 in several east Asian countries. ParseDate uses your computer's regional settings to determine the ordering of date components when parsing. You can override this by specifying the optional «dateTemplate» parameter, which should contain the characters 'd', 'M' and 'y' in the desired order. In other words, it should be 'dMy', 'Mdy' or 'yMd', or for you prefer for style reasons you can include dashes or include multiple characters, e.g., 'd/MM/yyyy', 'M/d/y', 'yyyy/M/d', etc.

ISO 8601 / RFC 3339 date-times with a time zone offset (new to Analytica 7.2): Text such as '2025-08-25T00:07:05.000+0000', '2025-08-25T00:07:05Z' or '2025-08-25T00:07:05.000-07:00', as returned by most web APIs, is now parsed. The zone designator must directly follow the time (no space before it) and may be Z, +HH:MM, +HHMM or +HH (with either sign). Because such text denotes an instant, it is converted into the time zone named by the optional «timeZone» parameter:

  • omitted or 'Model': the model's Sys_TimeZone setting (whose default, 'Local', is this computer's zone).
  • 'Local': this computer's time zone, with its daylight-saving rules.
  • 'UTC' (also 'Z' or 'GMT').
  • A fixed offset from UTC such as '+05:30', '-08:00', '+0530' or '-8'.

Text without an offset is returned as written, whatever «timeZone» is. A trailing Z was accepted but ignored in Analytica 7.0 and 7.1; as of 7.2 it means UTC, so such results may shift by your zone's offset from UTC.

Examples

ParseDate("1 Aug 2007") → 1-Aug-2007
ParseDate("8/1/2007") → 1-Aug-2007
ParseDate("1 Aug 2007") * 1 → 37833

The second example assumes English-language regional settings. The third example assumes that the "Use Excel date origin" preference is off, and exposes the underlying numeric value by using multiplication to force a conversion of the date-time value to a number.


ParseDate("8/1/2007", dateTemplate:"dMy") → 8-Jan-2007
Local data := ["Sky plant", "12/25/2016", 1.34M] Do ParseDate(data, data) → ["Sky plant", 25-Dec-2016, 1.34M]


ParseDate('2025-08-25T00:07:05.000+0000') → 24-Aug-2025 17:07:05 (with Sys_TimeZone = 'Local' on a computer in the US Pacific zone)
ParseDate('2025-08-25T00:07:05.000+0000', timeZone: 'UTC') → 25-Aug-2025 00:07:05
ParseDate('2025-08-25T00:07:05-07:00', timeZone: '+05:30') → 25-Aug-2025 12:37:05
ParseDate('2025-08-25T00:07:05') → 25-Aug-2025 00:07:05 (no offset, so no conversion)

Notes

ParseDate is useful when parsing data read in from textual files.

There are other ways of entering and parsing dates. You can enter dates directly into definitions or edit table cells when the variable's number format is set to Date. This is generally how dates are entered in models, rather than through the use of ParseDate.

History

  • The «timeZone» parameter and the parsing of ISO 8601 / RFC 3339 time zone offsets were added in Analytica 7.2.

See Also

Comments
Loading comments...