This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
dev:sql:functions:compare_dates [2010/04/08 20:19] els |
dev:sql:functions:compare_dates [2010/07/27 17:51] els |
||
---|---|---|---|
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. | + | |
- | ^ Unit ^ Description ^ | + | Optional. One of the following tokens representing the unit for the date arithmetic. |
- | | YEAR | Year | | + | |
- | | MONTH | Month | | + | |
- | | DAY | Day | | + | |
- | | HOUR | Hour | | + | |
- | | MINUTE | Minute | | + | |
- | | SECOND | Second | | + | |
- | | A | Lowercase am/pm indicator | | + | |
- | | AA | Uppercase AM/PM indicator | | + | |
- | | D | Non-zero-filled day-of-month (1, 2, 3) | | + | |
- | | 0D | Zero-filled day-of-month (01, 02, 03) | | + | |
- | | DD | Day of year (44) | | + | |
- | | 0DD | Zero-filled day of year (044) | | + | |
- | | F | Non-zero-filled fraction of a second (1, 2) | | + | |
- | | 0F | Zero-filled fraction of a second (01, 02) | | + | |
- | | H | 12-hour, non-zero-filled hour of day (12, 1) | | + | |
- | | 0H | 12-hour, zero-filled hour of day (12, 01) | | + | |
- | | HH | 24-hour, non-zero-filled hour of day (24, 1) | | + | |
- | | 0HH | 24-hour, zero-filled hour of day (24, 01) | | + | |
- | | J | Non-zero-filled Julian date (1, 2) | | + | |
- | | 0J | Zero-filled Julian date (01, 02) | | + | |
- | | M | Non-zero-filled month number (1-January, 2-February) | | + | |
- | | 0M | Zero-filled day-of-month number (01-January, 02-February) | | + | |
- | | MM | Three-character month abbreviation (Jan, Feb) | | + | |
- | | MMM | Fully spelled month (January, February) | | + | |
- | | N | Non-zero-filled minute of hour (1, 2) | | + | |
- | | 0N | Zero-filled minute of hour (01, 02) | | + | |
- | | Q | Quarter of the year (1) | | + | |
- | | QQ | Quarter of the year abbreviation (Q1) | | + | |
- | | QQQ | Quarter of the year name (First Quarter) | | + | |
- | | S | Non-zero-filled second of minute (1, 2) | | + | |
- | | 0S | Zero-filled second of minute (01, 02) | | + | |
- | | W | Day of the week number (1-Sunday, 2-Monday) | | + | |
- | | WW | Three-character day-of-week abbreviation (Sun, Mon) | | + | |
- | | WWW | Fully spelled day-of-week (Sunday, Monday) | | + | |
- | | YY | Two-digit year (99, 00) | | + | |
- | | YYYY | Four-digit year (1999, 2000) | | + | |
- | == options == | + | {{page>dev:appendix:reference:date_tokens_insert&noheader&nofooter&noeditbtn}} |
- | 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. | + | |
===== 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}} | ||
+ |