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
Next revision Both sides next revision
dev:sql:functions:calc_date [2009/12/18 15:22]
tdo
dev:sql:functions:calc_date [2010/07/27 17:37]
els
Line 1: Line 1:
 +{{page>:​top_add&​nofooter&​noeditbtn}}
 +{{page>:​sql_bar&​nofooter&​noeditbtn}}
 +====== Omnidex SQL Function: $CALC_DATE ======
 +===== Description =====
 +The $CALC_DATE function performs arithmetic on a date expression, returning a new date value. ​ The arithmetic is performed using the units declared in the function, or using DAYS if not specified.
 +
 +This function returns the same datatype as the passed date expression.
 +
 +===== Syntax =====
 +
 +  $CALC_DATE(date_expression,​ numeric_expression [, date_token] )
 +
 +== date_expression ==
 +
 +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]]. ​
 +
 +== numeric_expression ==
 +
 +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]]. ​
 +
 +If this function is to return a date in the future, the numeric expression should return a positive value. ​ If this function is to return a date in the past, the numeric expression should return a negative value.
 +
 +== date_tokens ==
 +
 +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: EXTRACT of MONTH ====
 +
 +<​code>​
 +> select birthdate, extract(month from birthdate) mon from individuals;​
 +
 +BIRTHDATE ​    MON
 +------------ ​ -----------
 +  1938-07-14 ​           7
 +  1957-11-22 ​          11
 +  1960-07-28 ​           7
 +  1929-08-22 ​           8
 +  1933-07-09 ​           7
 +  1944-08-01 ​           8
 +  2004-09-14 ​           9
 +</​code>​
 +==== Example 2: EXTRACT with format string ====
 +
 +<​code>​
 +> select birthdate, extract ('MMM D, YYYY' from birthdate) bday from individuals;​
 +
 +BIRTHDATE ​    BDAY
 +------------ ​ -------------------
 +  1938-07-14 ​ July 14, 1938
 +  1957-11-22 ​ November 22, 1957
 +  1960-07-28 ​ July 28, 1960
 +  1929-08-22 ​ August 22, 1929
 +  1933-07-09 ​ July 9, 1933
 +  1944-08-01 ​ August 1, 1944
 +  2004-09-14 ​ September 14, 2004
 +</​code>​
 +
 +====== Additional Resources ======
 +
 +See also:
 +{{page>​dev:​sql:​functions:​see_also_dates&​noheader&​nofooter&​noeditbtn}}
 +
 +
 +{{page>:​bottom_add&​nofooter&​noeditbtn}}
 +======
 +
 +
 +
 {{page>:​top_add&​nofooter&​noeditbtn}} {{page>:​top_add&​nofooter&​noeditbtn}}
 <​html><​div align="​center"><​span style="​color:​red">​DRAFT</​span></​div></​html>​ <​html><​div align="​center"><​span style="​color:​red">​DRAFT</​span></​div></​html>​
Line 7: Line 84:
  
 $CALC_DATE calculates a new date from a specified date or column_date using a numeric positive or negative offset. ​ The offset defaults to days but can be changed by using the date_unit optional argument. $CALC_DATE calculates a new date from a specified date or column_date using a numeric positive or negative offset. ​ The offset defaults to days but can be changed by using the date_unit optional argument.
- 
 ===== Syntax ===== ===== Syntax =====
  
 Result = $calc_date( <​date_column | '​date_string'​ >, offset_expression [, date_unit [, options]) Result = $calc_date( <​date_column | '​date_string'​ >, offset_expression [, date_unit [, options])
- +
 Returns a floating point value. Returns a floating point value.
  
Line 27: Line 103:
 A string containing unit abbreviation that tell the $calc_date function to add or subtract the number of date_units. A string containing unit abbreviation that tell the $calc_date function to add or subtract the number of date_units.
  
-Valid datefield Options+Valid date_unit options
-Date_field ​^ Description ^+Date_unit ​^ Description ^
 | YEAR | Year | | YEAR | Year |
 | MONTH | Month | | MONTH | Month |
Line 35: Line 111:
 | MINUTE | Minute | | MINUTE | Minute |
 | SECOND | Second | | SECOND | Second |
-Day of the week number (1-Sunday, 2-Monday) ​|  +Lowercase am/pm indicator ​
-WW Three-character day-of-week abbreviation (Sun, Mon) | +AA Uppercase AM/PM indicator ​|
-| 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) | | D | Non-zero-filled day-of-month (1, 2, 3) |
 | 0D | Zero-filled day-of-month (01, 02, 03) | | 0D | Zero-filled day-of-month (01, 02, 03) |
-Non-zero-filled Julian date (1, 2) | +DD Day of year (44) | 
-0J | Zero-filled ​Julian date (01, 02) | +0DD | Zero-filled ​day of year (044) | 
-YY Two-digit year (9900) | +Non-zero-filled fraction of a second ​(12) |  
-YYYY Four-digit year (19992000) | +0F Zero-filled fraction of a second ​(0102) |
 | H | 12-hour, non-zero-filled hour of day (12, 1) | | H | 12-hour, non-zero-filled hour of day (12, 1) |
 | 0H | 12-hour, zero-filled hour of day (12, 01) | | 0H | 12-hour, zero-filled hour of day (12, 01) |
 | HH | 24-hour, non-zero-filled hour of day (24, 1) |  | HH | 24-hour, non-zero-filled hour of day (24, 1) | 
 | 0HH | 24-hour, zero-filled hour of day (24, 01) | | 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) | | N | Non-zero-filled minute of hour (1, 2) |
 | 0N | Zero-filled minute of hour (01, 02) | | 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) |  | S | Non-zero-filled second of minute (1, 2) | 
 | 0S | Zero-filled second of minute (01, 02) | | 0S | Zero-filled second of minute (01, 02) |
-Non-zero-filled fraction ​of a second ​(1, 2) |  +Day of the week number ​(1-Sunday, 2-Monday) |  
-0F Zero-filled fraction ​of a second ​(0102) | +WW Three-character day-of-week abbreviation ​(SunMon) | 
-Lowercase am/pm indicator ​+WWW Fully spelled day-of-week (Sunday, Monday) ​|  
-AA Uppercase AM/PM indicator ​|+YY Two-digit year (99, 00) | 
 +| YYYY | Four-digit year (1999, 2000) 
  
  
 
Back to top
dev/sql/functions/calc_date.txt · Last modified: 2016/06/28 22:38 (external edit)