Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
dev:sql:functions:calc_date [2009/12/18 15:13]
tdo
dev:sql:functions:calc_date [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>​ +====== ​Development: ​Omnidex SQL ======
-====== Omnidex SQL Function: $CALC_DATE ====== +
-{{page>:​sql_bar&​nofooter&​noeditbtn}} +
-====Description ​=====+
  
-Result ​= $calc_date(date,​ value [, unit [, options]) +===== SQL Functions: ​$CALC_DATE ======
-  +
-Returns a floating point value.+
  
-===== Syntax ===== +==== Description ​==== 
-  $calc_date( <​date_column_spec | '​date_string'​ > value_expression [, date_unit [options ] )+The $CALC_DATE function performs arithmetic on a date expressionreturning a new date value. ​ The arithmetic is performed using the units declared in the functionor using DAYS if not specified.
  
-== <​date_column_spec | '​date_string'​ > == +This function returns the same datatype ​as the passed date expression.
-An expression resulting in date-class or string-class ​datatype.+
  
-  +==== Syntax ====
-== value_expression ​== +
-An expression resulting in a numeric-class (integer or floating point) value.  ​+
  
-Negative values supported. +  $CALC_DATE( date_expression,​ numeric_expression [ , date_token ] )
-== date_unit ==+
  
-A string containing unit abbreviation ​+== date_expression ==
  
-Valid datefield Options: +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]]. ​
-^ Date_field ^ Description ^ +
-| YEAR | | +
-| MONTH | | +
-| DAY | | +
-| HOUR | | +
-| MINUTE | | +
-| SECOND | | +
-| 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) |  +
-| 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) | +
-| D | Non-zero-filled day-of-month (1, 2, 3) | +
-| 0D | Zero-filled day-of-month (01, 02, 03) | +
-| J | Non-zero-filled Julian ​date (1, 2) | +
-| 0J | Zero-filled Julian ​date (01, 02) | +
-| YY | Two-digit year (99, 00) | +
-| YYYY | Four-digit year (1999, 2000) |  +
-| 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) | +
-| N | Non-zero-filled minute of hour (1, 2) | +
-| 0N | Zero-filled minute of hour (01, 02) | +
-| S | Non-zero-filled second of minute (1, 2) |  +
-| 0S | Zero-filled second of minute (01, 02) | +
-| F | Non-zero-filled fraction of a second (1, 2) |  +
-| 0F | Zero-filled fraction of a second (01, 02) | +
-| A | Lowercase am/pm indicator | +
-| AA | Uppercase AM/PM indicator ​|+
  
 +== numeric_expression ==
  
-== Options == +Required. Any expression that returns a numeric-class datatype. Examples of numeric expressions are columns, functions or expressions that return a numeric-class datatype. ​ The numeric datatypes ​are found in the list of [[dev:​appendix:​reference:​datatypes|Omnidex datatypes]]
-There are no options currently for this function. +
- +
  
-===== Example ===== +If this function is to return a date in the futurethe numeric expression should return a positive value. ​ If this function is to return a date in the pastthe numeric expression should return a negative value.
-==== Example 1 ==== +
-<​code>​ +
-> select $calc_date('​20090101'​-5,YEAR) from $omnidex+
  
-$CALC_DATE('​20090101',​ +== date_token ==
----------------------- +
-            2004-01-01+
  
 +Optional. One of the following tokens representing the unit for the date arithmetic.
 +
 +{{page>​dev:​appendix:​reference:​date_tokens_insert&​noheader&​nofooter&​noeditbtn}}
 +
 +
 +== date_column ==
 +
 +Required. A column that is declared as 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]]. ​
 +
 +
 +==== Example ====
 +=== Example 1: $CALC_DATE adding 18 years ===
 +
 +<​code>​
 +> select birthdate, $calc_date(birthdate,​ 18, '​YY'​) bday_plus_18 from individuals;​
 +
 +BIRTHDATE ​    ​BDAY_PLUS_18
 +------------ ​ ------------
 +  1938-07-14 ​   1956-07-14
 +  1957-11-22 ​   1975-11-22
 +  1960-07-28 ​   1978-07-28
 +  1929-08-22 ​   1947-08-22
 +  1933-07-09 ​   1951-07-09
 +  1944-08-01 ​   1962-08-01
 +  2004-09-14 ​   2022-09-14
 </​code>​ </​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}}
 +
 
Back to top
dev/sql/functions/calc_date.1261149196.txt.gz · Last modified: 2016/06/28 22:38 (external edit)