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:extract [2009/12/04 23:17]
tdo
dev:sql:functions:extract [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: EXTRACT ====== 
 {{page>:​sql_bar&​nofooter&​noeditbtn}} {{page>:​sql_bar&​nofooter&​noeditbtn}}
 +====== Omnidex SQL Function: EXTRACT ======
 ===== Description ===== ===== Description =====
-The EXTRACT function extracts ​an individual ​field value from a specified date_class data type.+The EXTRACT function extracts ​one or more portions of a date, such as a day, month or year.   This is useful for performing logic on portions of a date, such as performing certain actions in certain months. ​ This is also useful for assembling a date string in a specific format. 
 + 
 +This function returns a different datatype based on the requested ​field value.
 ===== Syntax ===== ===== Syntax =====
-  EXTRACT(date_field FROM date) 
  
-== date_field ​== +  EXTRACT(date_tokens FROM date_expression) 
-Required. ​The date part that is to be extracted. See below for a complete list of date parts that can be used in this parameter. Click to see a list of valid datefield options.+ 
 +== date_tokens ​== 
 + 
 +Required. ​One or more tokens representing the portions of date to be extracted, as determined by one or more of the strings shown in the table below.  //​Date_tokens//​ may also contain punctuation marks to create simple format string ​for dates, as shown in the examples below. ​ When punctuation marks are used, //​date_tokens//​ should be enclosed in single quotes. 
 + 
 +{{page>​dev:​appendix:​reference:​date_tokens_insert&​noheader&​nofooter&​noeditbtn}} 
 + 
 + 
 +== date_expression == 
 + 
 +Required. Any expression that returns ​date-class datatype. Examples ​of date expressions are columns or functions ​that return ​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>​ <​code>​
-Valid datefield Options: +> select birthdate, extract(month from birthdatemon from individuals;​ 
-| YEAR | | + 
-| MONTH | | +BIRTHDATE ​    MON 
-| DAY | | +------------ ​ ----------- 
-| HOUR | | +  1938-07-14            7 
-| MINUTE | | +  1957-11-22           11 
-| SECOND | | +  1960-07-28            7 
-| W | Day of the week number ​(1-Sunday, 2-Monday +  1929-08-22            8 
-| WW | Three-character day-of-week abbreviation (Sun, Mon) | +  1933-07-09            7 
-| WWW | Fully spelled day-of-week (Sunday, Monday) |  +  1944-08-01            8 
-| M | Non-zero-filled month number (1-January, 2-February) |  +  2004-09-14            9
-| 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 |+
 </​code>​ </​code>​
-== FROM == +==== Example 2: EXTRACT with format string ====
-Required.+
  
-== date == +<​code>​ 
-Required. A date formatted as any valid SQL92 date_class data type.+> 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}}
  
-If the original date is an OMNIDEX DATE or OMNIDEX DATETIME column, the return data type is C STRING length 32. Otherwise, the return data type is as follows: 
  
-===== Example ===== 
-==== Example 1 ==== 
 {{page>:​bottom_add&​nofooter&​noeditbtn}} {{page>:​bottom_add&​nofooter&​noeditbtn}}
 
Back to top
dev/sql/functions/extract.1259968633.txt.gz · Last modified: 2016/06/28 22:38 (external edit)