Oracle date addition and subtraction

Source: Internet
Author: User
Oracle date addition and subtraction method 2011-04-1808: 40 addition selectsysdate, add_months (sysdate, 12) fromdual; -- add 1 year selectsysdate, add_months (sysdate, 1) fromdual; -- add January selectsysdate, to_char (sysdate7, yyyy-mm-ddHH24: MI: SS) fromdual; -- add 1 star

Oracle date addition and subtraction method addition select sysdate, add_months (sysdate, 12) from dual; -- add 1 year select sysdate, add_months (sysdate, 1) from dual; -- add select sysdate, to_char (sysdate7, 'yyyy-mm-dd HH24: MI: ss') from dual; -- add 1 star

Oracle

Date addition and subtraction method

Addition

Select sysdate, add_months (sysdate, 12) from dual;

--

Add

1

Year

Select sysdate, add_months (sysdate, 1) from dual;

--

Add

1

Month

Select sysdate, to_char (sysdate + 7, 'yyyy-mm-dd HH24: MI: ss') from dual;

--

Add

1

Week

Select sysdate, to_char (sysdate + 1, 'yyyy-mm-dd HH24: MI: ss') from dual;

--

Add

1

Days

Select sysdate, to_char (sysdate + 1/24, 'yyyy-mm-dd HH24: MI: ss') from dual;

--

Add

1

Hours

Select sysdate, to_char (sysdate + 1/24/60, 'yyyy-mm-dd HH24: MI: ss') from dual;

--

Add

1

Minutes

Select sysdate, to_char (sysdate + 1/24/60/60, 'yyyy-mm-dd HH24: MI: ss') from dual;

--

Add

1

Seconds

Subtraction

Select sysdate, add_months (sysdate,-12) from dual;

--

Subtraction

1

Year

Select sysdate, add_months (sysdate,-1) from dual;

--

Subtraction

1

Month

Select sysdate, to_char (sysdate-7, 'yyyy-mm-dd HH24: MI: ss') from dual;

--

Subtraction

1

Week

Select sysdate, to_char (sysdate-1, 'yyyy-mm-dd HH24: MI: ss') from dual;

--

Subtraction

1

Days

Select sysdate, to_char (sysdate-1/24, 'yyyy-mm-dd HH24: MI: ss') from dual;

--

Subtraction

1

Hours

Select sysdate, to_char (sysdate-1/24/60, 'yyyy-mm-dd HH24: MI: ss') from dual;

--

Subtraction

1

Minutes

Select

Sysdate, to_char (sysdate-1/24/60/60, 'yyyy-mm-dd

HH24: MI: ss ')

From

Dual;

--

Subtraction

1

Seconds

The date and date cannot be added together.

Date and number can be added.

SQL>

Select

Sysdate + 1

From

Dual;

Date and date can be subtracted

SQL>

Select

Sysdate-sysdate

From

Dual;

Add_Months

(

D

,

X

)

Return

D

Date plus

X

Date after month

Last_Day

(

D

)

Returns the date of inclusion.

D

The date of the last day of the month.

Add_months (sysdate, 1)

Add a month

Add_months (sysdate,-1)

Minus one month

Sysdate + 1

Add one day

-------------------------------------------------------------------------------

Months_Between

(

D1

,

D2

)


Return

D1

,

D2

The number of months.

New_Time

(

D

,

Z1

,

Z2

)

Return Time Zone

Z1

Time is

D

Hour

Z2

Time Zone

Next_Day

(

D

,

S

)

Returns

S

Next day

S

The day of the week.

Round

(

D

,

F

)

Date

D

By format

F

Round

Sysdate

Returns the current database time.

Trunc

(

D

,

F

)

By format

F

Truncation time

D

In addition, the date can be directly added or subtracted

For example:

Sysdate

+ 1, sysdate

-1

------------------------------------------------------------

Sysdate + 1

Add one day

Sysdate + 1/24

Add

1

Hours

Sysdate + 1/(24*60)

Add

1

Minutes

Sysdate + 1/(24*60*60)

Add

1

Seconds

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.