ParseDate - Maple Help

Finance

 ParseDate
 parse a string containing date information

 Calling Sequence ParseDate(date) ParseDate(date, format)

Parameters

 date - a string containing a date specification; date specification format - deduce, default, or a string; (optional) date format

Description

 • The ParseDate command parses the string date assumed to contain date information according to the parsing specification given by the format string format. The date format can be any format specification as described in StringTools[ParseTime].
 • If the format string is missing, several standard date formats are tried. The first format to succeed will be used. The "standard" date formats are "%d-%b-%Y", "%d-%b-%y", "%d-%m-%Y", "%d-%m-%y", "%b-%d-%Y", "%b-%d-%y", "%Y-%b-%d", and "%Y-%m-%d", and its variations obtained by replacing all minus signs by one of the characters " " (space), "," (comma), "/" (slash), or ":" (colon).
 • The record returned by ParseDate contains slots with the following meanings and ranges of values:

 monthDay day of the month 1..31 month month of the year 1..12 year the year 0..9999 format date format deduce or string

Notes

 • If you call ParseDate multiple times with the same input, then typically the same record will be returned. For this reason, you should not modify the record returned by ParseDate: if you do, then the next call will likely get the modified record back. Instead, if you need to modify the result, then do this with a copy of the record. You can create such a copy, for example, with the calling sequence copy(ParseDate(...)).

Examples

 > $\mathrm{with}\left(\mathrm{Finance}\right):$
 > $\mathrm{Date1}≔\mathrm{ParseDate}\left("Jan-02-2006"\right)$
 ${\mathrm{Date1}}{≔}{\mathrm{Record}}{}\left({\mathrm{weekDay}}{=}{2}{,}{\mathrm{monthDay}}{=}{2}{,}{\mathrm{month}}{=}{1}{,}{\mathrm{year}}{=}{2006}{,}{\mathrm{format}}{=}{"%b-%d-%Y"}\right)$ (1)
 > $\mathrm{FormatDate}\left(\mathrm{Date1}\right)$
 ${"Jan-02-2006"}$ (2)
 > $\mathrm{Date1}:-\mathrm{format}$
 ${"%b-%d-%Y"}$ (3)
 > $\mathrm{FormatDate}\left(\mathrm{Date1},\mathrm{default}\right)$
 ${"January 2, 2006"}$ (4)
 > $\mathrm{FormatDate}\left("Jan-02-2006",\mathrm{default}\right)$
 ${"January 2, 2006"}$ (5)
 > $\mathrm{Date2}≔\mathrm{ParseDate}\left("2006/01/02","%Y/%m/%d"\right)$
 ${\mathrm{Date2}}{≔}{\mathrm{Record}}{}\left({\mathrm{weekDay}}{=}{2}{,}{\mathrm{monthDay}}{=}{2}{,}{\mathrm{month}}{=}{1}{,}{\mathrm{year}}{=}{2006}{,}{\mathrm{format}}{=}{"%Y/%m/%d"}\right)$ (6)
 > $\mathrm{Date2}:-\mathrm{month}$
 ${1}$ (7)
 > $\mathrm{Date3}≔\mathrm{ParseDate}\left("01-02-06","%m-%d-%y"\right)$
 ${\mathrm{Date3}}{≔}{\mathrm{Record}}{}\left({\mathrm{weekDay}}{=}{2}{,}{\mathrm{monthDay}}{=}{2}{,}{\mathrm{month}}{=}{1}{,}{\mathrm{year}}{=}{2006}{,}{\mathrm{format}}{=}{"%m-%d-%y"}\right)$ (8)

You can change the default date format by using the Finance[Settings] command.

 > $\mathrm{Settings}\left(\mathrm{dateformat}="%D"\right)$
 ${"%B %e, %Y"}$ (9)
 > $\mathrm{FormatDate}\left(\mathrm{Date1},\mathrm{default}\right)$
 ${"01/02/06"}$ (10)
 > $\mathrm{FormatDate}\left("Jan-02-2006",\mathrm{default}\right)$
 ${"01/02/06"}$ (11)

By default, the deduced date format will be used.

 > $\mathrm{FormatDate}\left(\mathrm{Date1}\right)$
 ${"Jan-02-2006"}$ (12)

Compatibility

 • The Finance[ParseDate] command was introduced in Maple 15.