This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
dev:sql:functions:compare_dates [2009/12/19 00:31] tdo created |
dev:sql:functions:compare_dates [2016/06/28 22:38] (current) |
||
---|---|---|---|
Line 1: | Line 1: | ||
{{page>:top_add&nofooter&noeditbtn}} | {{page>:top_add&nofooter&noeditbtn}} | ||
- | <html><div align="center"><span style="color:red">DRAFT</span></div></html> | ||
- | ====== Omnidex SQL Function: $COMPARE_DATE ====== | ||
{{page>:sql_bar&nofooter&noeditbtn}} | {{page>:sql_bar&nofooter&noeditbtn}} | ||
+ | ====== Omnidex SQL Function: $COMPARE_DATES ====== | ||
===== Description ===== | ===== Description ===== | ||
+ | The $COMPARE_DATES function compares two date expression and returns the difference. The arithmetic is performed using the units declared in the function, or using days if not specified. | ||
+ | |||
+ | This function returns an INTEGER datatype. | ||
- | The $COMPARE_DATES function determines the interval between two dates and returns that value as a fractional floating point value. The interval will default to days unless overridden using the unit parameter. | ||
===== Syntax ===== | ===== Syntax ===== | ||
- | $COMPARE_DATES ( <date_column1 | 'date_string1' > , < date_column2 | 'date_string2 > | + | $COMPARE_DATE( date_expression_1, date_expression_2 [ , date_token ] ) |
- | [, [date_unit] | + | |
- | [, options] | + | |
- | ) | + | |
- | ===== Discussion ===== | + | == date_expression_1 and date_expression_2 == |
- | == < date_column1 | 'date_string1' > == | + | |
- | An expression resulting in a date-class or string-class datatype | + | |
- | == < date_column2 | 'date_string2' > == | + | Required. Any expression that returns a date-class datatype. Examples of date expressions are columns or functions that return a date-class datatype. The date-class datatypes are any of the date or time oriented datatypes found in the list of [[dev:appendix:reference:datatypes|Omnidex datatypes]]. |
- | An expression resulting in a date-class or string-class datatype | + | |
- | == date_unit == | + | == date_token == |
- | A string containing a unit abbreviation identifying the type of interval. The supported abbreviations are the same as those found in the EXTRACT function. | + | |
- | == options == | + | Optional. One of the following tokens representing the unit for the date arithmetic. |
- | A string containing options for this functions. No options exist at this time. | + | |
- | The result of the $COMPARE_DATES function is an INTEGER datatype reflecting the number of units between the two dates. | + | {{page>dev:appendix:reference:date_tokens_insert&noheader&nofooter&noeditbtn}} |
===== Example ===== | ===== Example ===== | ||
- | ==== Example 1 ==== | + | ==== Example 1: $COMPARE_DATES calculating age ==== |
+ | |||
+ | <code> | ||
+ | > select birthdate, $compare_dates(birthdate, current_date, 'YY') age from individuals; | ||
+ | |||
+ | BIRTHDATE AGE | ||
+ | ------------ ----------- | ||
+ | 1938-07-14 72 | ||
+ | 1957-11-22 53 | ||
+ | 1960-07-28 50 | ||
+ | 1929-08-22 81 | ||
+ | 1933-07-09 77 | ||
+ | 1944-08-01 66 | ||
+ | 2004-09-14 6 | ||
+ | </code> | ||
+ | |||
+ | ====== Additional Resources ====== | ||
+ | |||
+ | See also: | ||
+ | {{page>dev:sql:functions:see_also_dates&noheader&nofooter&noeditbtn}} | ||
{{page>:bottom_add&nofooter&noeditbtn}} | {{page>:bottom_add&nofooter&noeditbtn}} | ||
+ |