The "Date2Num()" function will convert a date with a specified format to the number of days since the Epoch date. This function has 1 required parameter of the date string and 2 optional parameters the date format string and the locale identifier. The date string must contain the entire date components of year, month and date and failure to supply all this date results in a return value of zero. If the raw or formatted date string is not in the expected format a value of zero will also be returned.
The "IsoDate2Num()" function will return the number of days from the Epoch date and has only one required parameter of the ISO date string and there are not optional parameters. The ISO date string can be any valid ISO date which can consist of the year, the year and month, or the year, month and day. If the month or month and day are omitted the omitted data is assumed to be 1.
Using the following FormCalc script for the "exit" script for a date field:
// build message string to displyvar Msg ="Using the $.rawValue:"Msg = Concat(Msg,"\u000d","rawValue: ", $.rawValue)// add carriage return and more dataMsg = Concat(Msg,"\u000d","Date2Num($.rawValue): ", Date2Num($.rawValue))Msg = Concat(Msg,"\u000d","IsoDate2Num($.rawValue): ", IsoDate2Num($.rawValue))Msg = Concat(Msg,"\u000d\u000d","Using the $.formatedValue:")Msg = Concat(Msg,"\u000d","$.formattedValue: ", $.formattedValue)Msg = Concat(Msg,"\u000d","Date2Num($.formattedValue, ""YYYY-MM-DD""): ", Date2Num($.formattedValue,"YYYY-MM-DD"))Msg = Concat(Msg,"\u000d","IsoDate2Num($.formattedValue): ", IsoDate2Num($.formattedValue))Msg = Concat(Msg,"\u000d","Date2Num($.formattedValue, ""MMM D, YYYY""): ", Date2Num($.formattedValue,"MMM D, YYYY"))// display messagexfa.host.messageBox(Msg,"Date2Num and IsoDate2Num Functions Example",3)
Will return the following display for various date formats and input dates
Using a Display Format of "MMM D, YYYY" for the date field and selecting Aug 2, 2008:
Quote:
Using the $.rawValue: rawValue: 2008-08-02 Date2Num($.rawValue): 0 IsoDate2Num($.rawValue): 39661
Using the $.formatedValue: $.formattedValue: Aug 2, 2008 Date2Num($.formattedValue, "YYYY-MM-DD"): 0 IsoDate2Num($.formattedValue): 0 Date2Num($.formattedValue, "MMM D, YYYY"): 39661
Entering "Aug, 2008":
Quote:
Using the $.rawValue: rawValue: Aug, 2008 Date2Num($.rawValue): 0 IsoDate2Num($.rawValue): 0
Using the $.formatedValue: $.formattedValue: Aug, 2008 Date2Num($.formattedValue, "YYYY-MM-DD"): 0 IsoDate2Num($.formattedValue): 0 Date2Num($.formattedValue, "MMM D, YYYY"): 0
Using a Display Format of "YYYY-MM-DD", the ISO date format, for the date field and Selecting Aug 2, 2008:
Quote:
Using the $.rawValue: rawValue: 2008-08-02 Date2Num($.rawValue): 0 IsoDate2Num($.rawValue): 39661
Using the $.formatedValue: $.formattedValue: 2008-08-02 Date2Num($.formattedValue, "YYYY-MM-DD"): 39661 IsoDate2Num($.formattedValue): 39661 Date2Num($.formattedValue, "MMM D, YYYY"): 0
Entering "2008-01-01":
Quote:
Using the $.rawValue: rawValue: 2008-8-01 Date2Num($.rawValue): 0 IsoDate2Num($.rawValue): 0
Using the $.formatedValue: $.formattedValue: 2008-8-01 Date2Num($.formattedValue, "YYYY-MM-DD"): 0 IsoDate2Num($.formattedValue): 0 Date2Num($.formattedValue, "MMM D, YYYY"): 0
Entering "2008-08":
Quote:
Using the $.rawValue: rawValue: 2008-08 Date2Num($.rawValue): 0 IsoDate2Num($.rawValue): 39660
Using the $.formatedValue: $.formattedValue: 2008-08-01 Date2Num($.formattedValue, "YYYY-MM-DD"): 39660 IsoDate2Num($.formattedValue): 39660 Date2Num($.formattedValue, "MMM D, YYYY"): 0
Entering "2008":
Quote:
Using the $.rawValue: rawValue: 2008 Date2Num($.rawValue): 0 IsoDate2Num($.rawValue): 39447
Using the $.formatedValue: $.formattedValue: 2008-01-01 Date2Num($.formattedValue, "YYYY-MM-DD"): 39447 IsoDate2Num($.formattedValue): 39447 Date2Num($.formattedValue, "MMM D, YYYY"): 0
The "IsoDate2Num()" function will return the number of days from the Epoch date and has only one required parameter of the ISO date string and there are not optional parameters. The ISO date string can be any valid ISO date which can consist of the year, the year and month, or the year, month and day. If the month or month and day are omitted the omitted data is assumed to be 1.
Using the following FormCalc script for the "exit" script for a date field:
Will return the following display for various date formats and input dates
Using a Display Format of "MMM D, YYYY" for the date field and selecting Aug 2, 2008:
rawValue: 2008-08-02
Date2Num($.rawValue): 0
IsoDate2Num($.rawValue): 39661
Using the $.formatedValue:
$.formattedValue: Aug 2, 2008
Date2Num($.formattedValue, "YYYY-MM-DD"): 0
IsoDate2Num($.formattedValue): 0
Date2Num($.formattedValue, "MMM D, YYYY"): 39661
rawValue: Aug, 2008
Date2Num($.rawValue): 0
IsoDate2Num($.rawValue): 0
Using the $.formatedValue:
$.formattedValue: Aug, 2008
Date2Num($.formattedValue, "YYYY-MM-DD"): 0
IsoDate2Num($.formattedValue): 0
Date2Num($.formattedValue, "MMM D, YYYY"): 0
rawValue: 2008-08-02
Date2Num($.rawValue): 0
IsoDate2Num($.rawValue): 39661
Using the $.formatedValue:
$.formattedValue: 2008-08-02
Date2Num($.formattedValue, "YYYY-MM-DD"): 39661
IsoDate2Num($.formattedValue): 39661
Date2Num($.formattedValue, "MMM D, YYYY"): 0
rawValue: 2008-8-01
Date2Num($.rawValue): 0
IsoDate2Num($.rawValue): 0
Using the $.formatedValue:
$.formattedValue: 2008-8-01
Date2Num($.formattedValue, "YYYY-MM-DD"): 0
IsoDate2Num($.formattedValue): 0
Date2Num($.formattedValue, "MMM D, YYYY"): 0
rawValue: 2008-08
Date2Num($.rawValue): 0
IsoDate2Num($.rawValue): 39660
Using the $.formatedValue:
$.formattedValue: 2008-08-01
Date2Num($.formattedValue, "YYYY-MM-DD"): 39660
IsoDate2Num($.formattedValue): 39660
Date2Num($.formattedValue, "MMM D, YYYY"): 0
rawValue: 2008
Date2Num($.rawValue): 0
IsoDate2Num($.rawValue): 39447
Using the $.formatedValue:
$.formattedValue: 2008-01-01
Date2Num($.formattedValue, "YYYY-MM-DD"): 39447
IsoDate2Num($.formattedValue): 39447
Date2Num($.formattedValue, "MMM D, YYYY"): 0
George Kaiser