Oracle's date comparison and processing

Source: Internet
Author: User

1, date comparison is accurate to day, you can use TRUNC (sysdate, ' dd ') function.
function support formats are: YYYY MM DD hh Mi
You can use Select TRUNC (sysdate, ' yyyy ') from the dual test to see

"Back": Date select Sysdate from dual--date

Select Trunc (sysdate) from dual

Select Trunc (sysdate, ' DD ') from dual--today's date

Select Trunc (sysdate, ' d ') +7 from dual--Sunday of the week

Select Trunc (sysdate, ' dy ') +7 from dual--Sunday of the week

Select Trunc (sysdate, ' Day ') +7 from dual--Sunday of the week

Select Trunc (sysdate, ' Q ') from dual--this season start date

Select Trunc (sysdate, ' month ') from dual--month start date

Select Trunc (sysdate, ' mm ') from dual--month start date

Select Trunc (Sysdate, ' year ') from dual--start date

Select Trunc (sysdate, ' yyyy ') from dual--year start date

Select Trunc (sysdate, ' HH24 ') from dual-This hour start time

Select Trunc (sysdate, ' MI ') from dual--this minute start time

Select Trunc (sysdate, ' CC ') from dual--time of the century

Select Trunc (Last_day (sysdate), ' DD ') from dual--last day of the month

2. Addition and subtraction of dates

Sysdate+1 Plus One day
SYSDATE+1/24 plus 1 hours
SYSDATE+1/(24*60) plus 1 minutes
SYSDATE+1/(24*60*60) plus 1 seconds

   addition
Select Sysdate,add_months (sysdate,12) from dual; --plus 1 years
Select Sysdate,add_months (sysdate,1) from dual; --Add January
Select Sysdate,to_char (sysdate+7, ' Yyyy-mm-dd HH24:MI:SS ') from dual; --plus 1 weeks
Select Sysdate,to_char (sysdate+1, ' Yyyy-mm-dd HH24:MI:SS ') from dual; --plus 1 days
Select Sysdate,to_char (sysdate+1/24, ' Yyyy-mm-dd HH24:MI:SS ') from dual; --plus 1 hours
Select Sysdate,to_char (sysdate+1/24/60, ' Yyyy-mm-dd HH24:MI:SS ') from dual; --plus 1 minutes
Select Sysdate,to_char (sysdate+1/24/60/60, ' Yyyy-mm-dd HH24:MI:SS ') from dual; --plus 1 seconds
Subtraction
Select Sysdate,add_months (sysdate,-12) from dual; -Minus 1 years
Select Sysdate,add_months (sysdate,-1) from dual; --Minus January
Select Sysdate,to_char (sysdate-7, ' Yyyy-mm-dd HH24:MI:SS ') from dual; -Minus 1 weeks
select Sysdate,to_char (sysdate-1, ' Yyyy-mm-dd HH24:MI:SS ') from dual; --minus 1 days
select Sysdate,to_char (sysdate-1/24 , ' Yyyy-mm-dd HH24:MI:SS ') from dual; -minus 1 hours
select Sysdate,to_char (sysdate-1/24 /60, ' Yyyy-mm-dd HH24:MI:SS ') from dual; -minus 1 minutes
select Sysdate,to_char (sysdate-1/24 /60/60, ' Yyyy-mm-dd HH24:MI:SS ') from dual; -minus 1 seconds

Oracle's date comparison and processing

Related Article

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.