This shows you the differences between two versions of the page.
dev:sql:functions:extract [2010/07/27 15:57] els |
dev:sql:functions:extract [2016/06/28 22:38] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | {{page>:top_add&nofooter&noeditbtn}} | ||
- | {{page>:sql_bar&nofooter&noeditbtn}} | ||
- | ====== Omnidex SQL Function: EXTRACT ====== | ||
- | ===== Description ===== | ||
- | 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 ===== | ||
- | |||
- | EXTRACT(date_tokens FROM date_expression) | ||
- | |||
- | == 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 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]]. | ||
- | |||
- | |||
- | ===== 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}} |