I l @ ve RuBoard |
The following functions assist in performing calculations based on time- and date-related material. These are useful in performing calculations and transformations of temporal- related data sets. AGEDescriptionThe AGE function returns an interval that represents the difference between the current time and the time argument supplied. InputsAGE(timestamp) ”Computes the difference between the timestamp supplied and now() . AGE(timestamp, timestamp) ”Computes the difference between the two supplied timestamps. ExampleAGE('03-01-2001 15:56:00', '11-01-2001 14:22:00') 7 mon 30 22:26 ago CURRENT_DATEDescriptionThe CURRENT_DATE function returns the current system date. InputsNone. ExampleSELECT CURRENT_DATE; 2001-06-11 NotesNotice that there are no trailing parentheses "()" with this function. This is to maintain SQL compatibility. CURRENT_TIMEDescriptionThe CURRENT_TIME function returns the current system time. InputsNone. ExampleSELECT CURRENT_TIME; 22:10:31 NotesNotice that there are no trailing parentheses "()" with this function. This is to maintain SQL compatibility. CURRENT_TIMESTAMPDescriptionThe CURRENT_TIMESTAMP function returns the current system date and time. InputsNone. ExampleSELECT CURRENT_TIMESTAMP; '2001-06-11 22:10:31-06' NotesNotice that there are no trailing parentheses "()" with this function. This is to maintain SQL compatibility. This function is analogous to the NOW function. DATE_PARTDescriptionThe DATE_PART function extracts a specified section from the supplied date/time argument. InputsDATE_PART( formattext, timestamp ) DATE_PART( formattext, interval ) formattext ”One of the valid DATE_PART formatting options; see the following section. timestamp/interval ”The supplied time-related value. DATE_PART Formatting Options The following keywords are recognized as valid date-time elements available for extraction:
ExamplesDATE_PART('second', TIMESTAMP '06-01-2001 12:23:43') 43 DATE_PART('hour', TIMESTAMP '06-01-2001 12:23:43') 12 NotesWhen using DATE_PART with interval data types, it is import to recognize that DATE_PART will not do implicit calculations. DATE_PART only functions as an extraction tool. For instance, if your interval is 1 month ago , DATE_PART will return 0 (zero) if you tried to extract days . DATE_TRUNCDescriptionThe DATE_TRUNC function truncates the supplied timestamp to the specified precision. InputsDATE_TRUNC(formattext, timestamp) formattext ”The precision value to which to truncate the timestamp; see the following valid options for formatting. timestamp ”The supplied date/time value to truncate. DATE_TRUNC Formatting Options The following is a listing of the various levels of precision that DATE_TRUNC can operate on:
ExamplesDATE_TRUNC('hour', TIMESTAMP '2001-11-1 23:11:45') TIMESTAMP '2001-11-1 23:00:00' DATE_TRUNC('year' TIMESTAMP '11-1-2001 23:11:45') TIMESTAMP '2001-01-01 00:00:00' EXTRACTDescriptionThe EXTRACT function extracts the specified value from the supplied timestamp or interval. InputsEXTRACT( formattext FROM timestamp ) EXTRACT( formattext FROM interval ) formattext ”A valid date field. Refer to DATE_PART for a listing of valid format codes. interval/timestamp ”The supplied time value. ExampleEXTRACT('hour' FROM TIMESTAMP '2001-11-1 23:33:45') 23 NotesThe EXTRACT function performs like the DATE_PART function. Either syntax can be used interchangeably. ISFINITEDescriptionThe ISFINITE function returns a Boolean value that indicates whether the supplied timestamp or interval represents a finite amount of time. InputsISFINITE( timestamp ) ISFINITE( interval ) ExampleISFINITE(TIMESTAMP '2002-05-05 23:13:44') t NOWDescriptionThe NOW function returns a timestamp that represents the current system time. InputsNone. ExampleSELECT now(); '2001-11-1 15:23:54-06' NotesThe NOW function is conceptually the same as CURRENT_TIMESTAMP . TIMEOFDAYDescriptionThe TIMEOFDAY function returns a high-precision date and time value. InputsNone. ExampleSELECT TIMEOFDAY(); 'Sun Mar 11 22:23:14.853452 2001 CST' TIMESTAMPDescriptionThe TIMESTAMP function works as a conversion routine to convert either date or date and time data types into a timestamp. InputsTIMESTAMP(date) TIMESTAMP(date, time) ExampleTIMESTAMP('06-01-2001','23:45:11') '2001-06-01 23:45:11' |
I l @ ve RuBoard |