Date Functions in DIAL
The following DIAL calc functions work specifically with dates.
Accepts a date in the ISO or DI standard date format (YYYY/MM/DD) and returns the number of days since December 30, 1899. You can subtract the date_value() of one date from the date_value() of another date to find the number of days difference between two dates.
For example:
calc.date_value("1899/12/31"); returns 1
calc.date_value("1900-07-04"); returns 186
calc.date_value("2006/10/26") - calc.date_value("1954/12/04"); returns 18954
(calc.date_value("2006/10/26") - calc.date_value("1954/12/04"))/365; returns 51.928767
Returns the two-digit day portion of date as a number. When printed, single digit days do not have a leading zero.
For example:
calc.day("1954/12/04"); returns 4
calc.day("1955-10-21"); returns 21
calc.day("2005/05/55"); returns 55
Takes a date_str in different formats (there are some limitations) and a string describing that format, and returns the date in DI’s standard date format (YYYY/MM/DD). For this and related functions, "y" represents a year, "m" represents a month, and "d" represents a day. You can sort records in date order by using the standard date format.
For example:
calc.format_date("3-17-94","mm-dd-yy"); returns 1994/03/17
calc.format_date("12/03/07","mm/dd/yy"); returns 1907/12/03
calc.format_date("551021","yymmdd"); returns 1955/10/21
Converts the calculated date_num into the standard DI date format.
For example:
This example takes a Gregorian date ( yyyyddd) and converts it to a Julian date.
calc.format_date_value(calc.date_value( calc.concat
(calc.substr("2006091",1,4),"/01/01") ) +
calc.substr("2006091",5,3) -1 ); returns 2006/04/01
Same as calc.format_date, except that it accepts two-digit years flexibly. Two-digit years are interpreted as being in a 100-year range starting from range.
For example:
calc.format_date_range("3-17-49", "mm-dd-yy", 1950); returns 2049/03/17
calc.format_date_range("1-27-55", "mm-dd-yy", 1950); returns 1955/01/27
calc.format_date_range("07-12-20", "yy-mm-dd", 1950); returns 2007/12/20
calc.format_date_range("760704", "yymmdd", 1700); returns 1776/07/04
Returns the number representing the day of the year between 1 and 366 for the specified date.
For example:
calc.julian_day("2012/01/15"); returns 15
calc.julian_day("2012-12-04"); returns 338
Returns the two-digit month portion of the date as a number. When printed, single digit months do not have a leading zero. .
For example:
calc.month("2007/09/26"); returns 9
calc.month("1977-11-7"); returns error
calc.month("1977-11-07"); returns 11
calc.month("2005/15/22"); returns 15
Returns the month name, in English, of the specified date.
For example:
calc.month_name("1776/07/04"); returns July
calc.month_name("2008-05-24"); returns May
Returns the one-digit calendar quarter in which date occurs. January through March is the first quarter, April through June is the second quarter, July through September is the third quarter, and October through December is the fourth quarter.
For example:
calc.quarter("2012/10/05"); returns 4
calc.quarter("2011-01-01"); returns 1
Returns the current date in standard date format (YYYY/MM/DD).
Returns the four-digit year portion of the date.
For example:
calc.year("2017/09/26"); returns 2017
calc.year("1977-11-07"); returns 1977