Você está na página 1de 6

http://www.java2s.com/Tutorial/Oracle/0260__Date-Timestamp-Functions/Catalog0260__DateTimestamp-Functions.

htm
http://www.java2s.com/Tutorials/Database/Oracle_Date_Time_Function/index.htm
https://docs.oracle. com/cd/B19306_01/server.102/b14225/ch4datetime.htm
------------------------------------------------------------------------------------------------------------------------------13.Date Timestamp Functions
13.1.Introduction( 7 )
13.2.ADD_MONTHS( 11 )
13.3.CURRENT_DATE( 1 )
13.4.CURRENT_TIMESTAMP( 2 )
13.5.DBTIMEZONE( 1 )
13.6.EXTRACT( 15 )
13.7.FROM_TZ( 1 )
13.8.LAST_DAY( 6 )
13.9.LOCALTIMESTAMP( 1 )
13.10.MONTHS_BETWEEN( 6 )
13.11.NEW_TIME( 3 )
13.12.NEXT_DAY( 7 )
13.13.NUMTODSINTERVAL( 5 )
13.14.NUMTOYMINTERVAL( 3 )
13.15.ROUND( 8 )
13.16.SESSIONTIMEZONE( 1 )
13.17.SYSDATE( 9 )
13.18.SYSTIMESTAMP( 1 )
13.19.SYS_EXTRACT_UTC( 1 )
13.20.TO_CHAR( 13 )
13.21.TO_DATE( 16 )
13.22.TO_TIMESTAMP( 1 )
13.23.TO_TIMESTAMP_TZ( 5 )
13.24.TRUNC( 10 )
13.25.TZ_OFFSET( 1 )
13.26.Date Arithmetic( 6 )
------------------------------------------------------------------------------------------------------------------------------13.Date Timestamp Functions
13.1.Introduction( 7 )
13.1.1.
Using Datetime Functions
13.1.2.
Timestamp-Related Functions
13.1.3.
Time Interval Related Functions
13.1.4.
Date Functions
13.1.5.
LAST_DAY, TO_CHAR, TO_DATE
13.1.6.
select date '1954-08-11' + 10000 as 10,000 days
13.1.7.
Differences Between Dates
13.2.ADD_MONTHS( 11 )
13.2.1.
ADD_MONTHS(x, y) gets the result of adding y months to x.
13.2.2.
Subtract 13 months from the January 1, 2005

13.2.3.
Combine ADD_MONTHS() function with To_Date
13.2.4.
Combine ADD_MONTHS() with TO_CHAR() and TO_DATE
13.2.5.
SELECT ADD_MONTHS('28-NOV-05', 1) FROM DUAL;
13.2.6.
SELECT ADD_MONTHS('29-NOV-05', 1) FROM DUAL;
13.2.7.
SELECT ADD_MONTHS('30-NOV-05', 1) FROM DUAL;
13.2.8.
SELECT ADD_MONTHS('31-DEC-05', -1) FROM DUAL;
13.2.9.
SELECT ADD_MONTHS('01-JAN-2005', 3) FROM dual;
13.2.10.SELECT ADD_MONTHS('01-JAN-2005', -3) FROM dual; (2)
13.2.11.Add Negative time
13.3.CURRENT_DATE( 1 )
13.3.1.
Getting the Current Date in the Session Time Zone
13.4.CURRENT_TIMESTAMP( 2 )
13.4.1.
CURRENT_TIMESTAMP()
13.4.2.
Insert a row using the CURRENT_TIMESTAMP function for both columns:
13.5.DBTIMEZONE( 1 )
13.5.1.
Get the database time zone using the DBTIMEZONE() function
13.6.EXTRACT( 15 )
13.6.1.
EXTRACT() to extract and return a year, month, day, hour, minute,
second, or time zone from
the timestamp types or a DATE.
13.6.2.
SELECT EXTRACT(MONTH FROM TO_DATE('01-JAN-2005 19:15:26','DDMON-YYYY HH24:MI:SS'))
As MONTH
13.6.3.
SELECT EXTRACT(YEAR FROM TO_DATE('01-JAN-2005 19:15:26','DDMON-YYYY HH24:MI:SS')) AS
YEAR
13.6.4.
EXTRACT() gets the hour, minute, and second from a TIMESTAMP
returned by TO_TIMESTAMP()
13.6.5.
EXTRACT(MINUTE FROM TO_TIMESTAMP('01-JAN-2005 19:15:26', 'DDMON-YYYY HH24:MI:SS'))
AS MINUTE
13.6.6.
EXTRACT(SECOND FROM TO_TIMESTAMP('01-JAN-2005 19:15:26', 'DDMON-YYYY HH24:MI:SS'))
AS SECOND
13.6.7.
EXTRACT()gets the time zone hour, minute, second, region, and region
abbreviation from a
TIMESTAMP WITH TIMEZONE returned by TO_TIMESTAMP_TZ()
13.6.8.
EXTRACT(TIMEZONE_MINUTE FROM TO_TIMESTAMP_TZ('01-JAN-2005
19:15:26 -7:15', 'DDMON-YYYY HH24:MI:SS TZH:TZM'))
13.6.9.
EXTRACT(TIMEZONE_REGION FROM TO_TIMESTAMP_TZ('01-JAN-2005
19:15:26 PST', 'DD-MONYYYY HH24:MI:SS TZR'))
13.6.10.EXTRACT(TIMEZONE_ABBR FROM TO_TIMESTAMP_TZ('01-JAN-2005 19:15:26
PST', 'DD-MONYYYY HH24:MI:SS TZR'))
13.6.11.extract year from birthday
13.6.12.extract month from birthday

13.6.13.extract day from birthday


13.6.14.Extract year, month, day from a date
13.6.15.Order date value by only year field with extract() function
13.7.FROM_TZ( 1 )
13.7.1.
FROM_TZ(x, time_zone) converts the TIMESTAMP x and time zone
specified by time_zone to a
TIMESTAMP WITH TIMEZONE.
13.8.LAST_DAY (6)
13.8.1.
The LAST_DAY function returns the last day of any month
13.8.2.
SELECT LAST_DAY('01-JAN-2005') FROM dual;
13.8.3.
Finding the Last Day of the Month Starting Summer
13.8.4.
Calculating the Number of Days of Summer in June
13.8.5.
LAST_DAY(column value)+1
13.8.6.
Combine LAST_DAY and ADD_MONTHS togetherY( 6 )
13.9.LOCALTIMESTAMP( 1 )
13.9.1.
LOCALTIMESTAMP()
13.10.MONTHS_BETWEEN( 6 )
13.10.1. MONTHS_BETWEEN(x, y): get the number of months between x and y.
13.10.2. Returned result is a negative number of months
13.10.3. Use the MONTHS_BETWEEN function
13.10.4. SELECT MONTHS_BETWEEN('15-JAN-2005', '25-MAY-2005')
13.10.5. months_between current time and birthday
13.10.6. Months between birthday and now
13.11.NEW_TIME( 3 )
13.11.1. The NEW_TIME Function
13.11.2. Converting a Datetime from One Time Zone to Another with NEW_TIME()
function
13.11.3. Time Change from Chicago to Los Angeles
13.12.NEXT_DAY( 7 )
13.12.1. NEXT_DAY(x, day): get the date of the next day following x;
13.12.2. next_day(sysdate,'SAT')
13.12.3. NEXT_DAY function
13.12.4. NEXT_DAY(start_date-1,'Tuesday')
13.12.5. Finding the First Monday in the Month of August
13.12.6. Finding the First Monday in the Month of September
13.12.7. The Proper Method to Find the First Monday in a Given Month
13.13.NUMTODSINTERVAL( 5 )
13.13.1.NUMTODSINTERVAL()
13.13.2.NUMTODSINTERVAL(1.5, 'DAY')
13.13.3.NUMTODSINTERVAL(3.25, 'HOUR')
13.13.4.NUMTODSINTERVAL(5, 'MINUTE')
13.13.5.NUMTODSINTERVAL(10.123456789, 'SECOND')
13.14.NUMTOYMINTERVAL( 3 )
13.14.1.NUMTOYMINTERVAL(x, interval_unit) converts the number x to an INTERVAL
YEAR TO MONTH

with the interval for x supplied in interval_unit.


13.14.2.NUMTOYMINTERVAL(3.25, 'MONTH')
13.14.3.NUMTOYMINTERVAL(1.5, 'YEAR')
13.15.ROUND( 8 )
13.15.1.The ROUND Function
13.15.2.Datetime Formatting Parameters for ROUND(x[, unit])
13.15.3.ROUND(x[, unit]) : round x. By default, x is rounded to the beginning of the
nearest day
13.15.4.Round date to day
13.15.5.Rounds May 25, 2005, to the first day in the nearest month
13.15.6.Rounding to the Nearest Minute
13.15.7.ROUND(date_in_1,'CC')
13.15.8.Round result from months_between
13.16.SESSIONTIMEZONE( 1 )
13.16.1.Get your session time zone using the SESSIONTIMEZONE() function
13.17.SYSDATE( 9 )
13.17.1.SYSDATE() returns the current datetime set in the operating system
13.17.2.last_day(sysdate)
13.17.3.Default Output of SYSDATE
13.17.4.Combining TO_CHAR to Format SYSDATE
13.17.5.Removing the Time from SYSDATE
13.17.6.Truncating to the Quarter
13.17.7.Adding Two Months to SYSDATE
13.17.8.Adding One Month
13.17.9.Finding the First Monday After the Current Date and Time
13.18.SYSTIMESTAMP( 1 )
13.18.1.SYSTIMESTAMP()
13.19.SYS_EXTRACT_UTC( 1 )
13.19.1.SYS_EXTRACT_UTC(x) converts the TIMESTAMP WITH TIMEZONE x to a
TIMESTAMP containing
the date and time in UTC.
13.20.TO_CHAR( 13 )
13.20.1.Formatting Dates with TO_CHAR
13.20.2.An alias is required when using TO_CHAR to 'pretty up' the output
13.20.3.TO_CHAR(Start_Date, 'dd Month yyyy')
13.20.4.TO_CHAR(Start_Date, 'dd month YY')
13.20.5.TO_CHAR(Start_Date, 'dd Mon')
13.20.6.TO_CHAR(Start_Date, 'dd RM yyyy')
13.20.7.TO_CHAR(Start_Date, 'Day Mon yyyy')
13.20.8.TO_CHAR(Start_Date, 'Day fmMonth dd, yyyy')
13.20.9.TO_CHAR(Start_Date, 'Mon ddsp yyyy')
13.20.10.TO_CHAR(Start_Date, 'ddMon yy hh24:mi:ss')
13.20.11.TO_CHAR(sysdate,'HH24:MI:SS')
13.20.12.select TO_CHAR(sysdate,'HH.MI.SS AM') from dual;
13.20.13.to_char(gather_date, 'mm/dd/yyyy hh:mi')
13.21.TO_DATE( 16 )

13.21.1.Specifying a Datetime Format for TO_DATE() function


13.21.2.Using the YY Format
13.21.3.Using the RR Format
13.21.4.TO_CHAR(TO_DATE('04-JUL-15', 'DD-MON-RR'), 'DD-MON-YYYY')
13.21.5.TO_DATE function to convert from characters to dates explicitly
13.21.6.TO_DATE(x[, format]) converts the x string to a datetime
13.21.7.TO_DATE() converts the strings 04-JUL-2006 to the date July 4, 2006
13.21.8.Specifying Times
13.21.9.TO_DATE() with INSERT statement
13.21.10.DBMS_OUTPUT.PUT_LINE(TO_DATE ('1/1'));
13.21.11.DBMS_OUTPUT.PUT_LINE(TO_DATE ('6/1996'));
13.21.12.DBMS_OUTPUT.PUT_LINE(TO_DATE ('12-APR-09'));
13.21.13.DBMS_OUTPUT.PUT_LINE(TO_DATE ('19991205'));
13.21.14.DBMS_OUTPUT.PUT_LINE(TO_DATE ('1/1/1'))
13.21.15.Birthday before 1940
13.21.16.Catch exception from to_date function
13.22.TO_TIMESTAMP( 1 )
13.22.1.TO_TIMESTAMP(x, format) convert the string x ( CHAR , VARCHAR2 ,
NCHAR , or NVARCHAR2 )
to a TIMESTAMP.
13.23.TO_TIMESTAMP_TZ( 5 )
13.23.1.TO_TIMESTAMP_TZ(x,[format]) convert x to a TIMESTAMP WITH TIMEZONE
with an optional
format for x.
13.23.2.SELECT TO_TIMESTAMP_TZ('2005-05-13 07:15:31.1234 -7:00', 'YYYY-MM-DD
HH24:MI:SS.FF
TZH:TZM')
13.23.3.Examples of converting time zones to character strings
13.23.4.TO_TIMESTAMP_TZ('2002-06-18 13:52:00.123456789 -5:00','YYYY-MM-DD
HH24:MI:SS.FF
TZH:TZM')
13.23.5.TO_TIMESTAMP_TZ('2002-06-18 13:52:00.123456789 US/Eastern
EDT','YYYY-MM-DD
HH24:MI:SS.FF TZR TZD')
13.24.TRUNC( 10 )
13.24.1.TRUNC() parameter list
13.24.2.TRUNC(x[, unit]) truncates x.
13.24.3.How Oracle Interprets Two-Digit Years
13.24.4.Truncates May 25, 2005, to the first day in the month
13.24.5.Truncates 7:45:26 P.M. on May 25, 2005 to the hour
13.24.6.Examples of the TRUNC function being applied to datetime values
13.24.7.TRUNC(date_in,'YYYY')
13.24.8.TRUNC(date_in,'MM')
13.24.9.TRUNC(): truncate May 25, 2005, to the first day in the year
13.24.10.Use TRUNC(date_variable) when you want to extract a date from a
timestamp
13.25.TZ_OFFSET( 1 )
13.25.1.Obtaining Time Zone Offsets using the TZ_OFFSET() function

13.26.Date Arithmetic( 6 )
13.26.1.Using Date Arithmetic
13.26.2.Subtracts two days from August 2, 2003
13.26.3.Subtract one date from another, yielding the number of days between the
two dates.
13.26.4.select date '1996-01-29' + interval '1' month as col_1
13.26.5.select date '1997-08-11' - interval '3' month as col_3
13.26.6.Second Tuesday of the Month

Você também pode gostar