oracle date function

1. sysdate: return the current date
2. add_months(d1,n1): return the new date after adding n1 months to the date d1
3. last_day(d1): return the last day of the month where the date of d1 is located
4. months_between( d1, d2): returns the number of months between the date d1 and the date d2, d1>d2 returns a positive number, otherwise returns a negative number
5, NEW_TIME(dt1, c1, c2): gives the time dt1 in the c1 time zone corresponding to the date and the c2 time zone time. dt1 is the date type, c1 and c2 are the time zone and its abbreviation, the time zone abbreviation is as follows:
    Atlantic Standard Time: AST or ADT
    Alaska_Hawaii Time: HST or HDT
    British Summer Time: BST or BDT
    US Mountain Time: MST or MDT
    US Central Time Zone : CST or CDT
    New World Standard Time: NST
    US Eastern Time: EST or EDT
    Pacific Standard Time: PST or PDT
    Greenwich Mean Time: GMT
    Yukou Standard Time: YST or YDT
Example: select sysdate bj_time, new_time(sysdate,'PDT' ,'GMT') los_angles from dual;
Result:


6. round(d1[,c1]): Gives the first date of the period after the date d1 is rounded by the parameter c1 (similar to the meaning of rounding the number), d1 is a date type , c1 is a character type, c1 defaults to j (that is, the date of the last 0 o'clock), and the value of c1 is as follows:
     Last 0:00 date: Cancel the parameter c1 or j, the example is as follows:




     the nearest Sunday: day or dy or d, the example is as follows:




     the date of the latest beginning of the month: month or mon or mm or rm; the date of
     the latest quarter: q; the
     date of the latest beginning of the year: syear or year or yyyy or yyy or yy or y (multiple y's indicate precision); date of the beginning of
     the most recent century: cc or scc.

7. trunc(d1[,c1]): Returns the date of the first day of the period (parameter c1) where the date d1 is located, d1 is a date type, c1 is a character type (parameter), c1 defaults to j (that is, the current date), c1 corresponds to parameter table:
    last 0 o'clock date: cancel parameter c1 or j
    nearest sunday: day or dy or d (weekly order: day, mon, tues, wed, thur, fri, sat)
    most recent beginning of the month date: month or mon or mm or rm
    date of the latest quarter: q date of the latest beginning of the year: syear or year or yyyy or yyy or yy or y (multiple y indicates precision)
    date of the beginning of the latest century: cc or scc
8, next_day(d1[,c1]): return The date d1 is in the next week, the day of the week (parameter c1) of the date
    d1 date type, c1 is a character type (parameter), c1 defaults to j (ie the current date)
    c1 corresponds to: Monday, Tuesday, Wednesday...Sunday
   Example: select sysdate current date, next_day(sysdate,'Monday') next Monday, next_day(sysdate,'Tuesday') next Tuesday, next_day(sysdate,'Wed') next Wednesday, next_day(sysdate,' Thursday') next Thursday, next_day(sysdate,'Friday') next Friday, next_day(sysdate,'Saturday') next Saturday, next_day(sysdate,'Sunday') next Sunday from dual;

9. extract(c1 from d1)
[function]: in date/time d1, the value of parameter (c1)
[parameter]: d1 date type (date)/date time type (timestamp), c1 is character type (parameter)
[parameter table]: c1 For the corresponding parameter table, see the example
[return]: character
[example] select extract(hour from timestamp '2001-2-16 2:38:40 ' ) hour,
                extract(minute from timestamp '2001-2-16 2:38 :40 ' ) minutes,
                extract(second from timestamp '2001-2-16 2:38:40 ' ) seconds,
                extract(DAY from timestamp '2001-2-16 2:38:40 ' ) days,
                extract(MONTH from timestamp '2001-2-16 2:38:40 ' ) month,
                extract(YEAR from timestamp '2001-2-16 2:38:40 ' ) year
        from dual;
        select extract (YEAR from date '2001 -2-16' ) from dual;
        select sysdate current date,
               extract(hour from systimestamp) hour,
               extract(DAY from sysdate ) day,
               extract(MONTH from sysdate ) month,
               extract(YEAR from sysdate ) year
        from dual;
Description: date only contains year, month, day, timestamp contains year, month, day, hour, minute, and second. Only year, month, and day can be obtained from sysdate and date date types, and year, month, day, hour, minute, and second can be obtained from systimestamp and timestamp.

10. localtimestamp
[function]: return the date and time in the session
[parameters]: no parameters, no brackets
[return]: date
[Example] select localtimestamp from dual;

11. current_timestamp
[Function]: Return the current date in the time zone of the current session with the data type timestamp with time zone
[Parameter]: No parameter, no brackets
[Return]: Date
[Example] select current_timestamp from dual;

12. current_date
[function]: return the current date in the current session time zone
[parameter]: no parameter, no brackets
[return]: date
[example] select current_date from dual;

13. dbtimezone
function]: return time zone
[parameter] : No parameter, no brackets
[Return]: Character type
[Example] select dbtimezone from dual;

14. SESSIONTIMEZONE
[Function]: Return the session time zone
[Parameter]: No parameter, no brackets
[Return]: Character type
[Example] select dbtimezone ,SESSIONTIMEZONE from dual;

15. INTERVAL c1 set1
[Function]: Change the date and time value
[Parameter]: c1 is a numeric string or a date and time string, and set1 is a date parameter
[parameter table]: set1 specific reference example
[return]: numeric value in date and time format, when the preceding + signs are in days or smaller units, they can be borrowed from numerical expressions, such as 1 for 1 day, 1/24 for 1 hour ,1/24/60 means 1 minute
[Example] select trunc(sysdate)+(interval '1' second), --add 1 second (1/24/60/60)
trunc(sysdate)+(interval '1' minute), -- add 1 minute (1/24/60)
trunc(sysdate)+(interval '1' hour), -- add 1 hour (1/24)
trunc(sysdate)+(INTERVAL '1' DAY) , --add 1 day (1)
trunc(sysdate)+(INTERVAL '1' MONTH), --add 1 month
trunc(sysdate)+(INTERVAL '1' YEAR), --add 1 year
trunc(sysdate)+ (interval '01:02:03' hour to second), --add the specified hour to second
trunc(sysdate)+(interval '01:02' minute to second), --add the specified minute to second
trunc(sysdate)+ (interval '01:02' hour to minute), --Add the specified hour to minute
trunc(sysdate)+(interval '2 01:02' day to minute) --Add the specified number of days to minutes
from dual;


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326521543&siteId=291194637