MySQL vs Oracle (III)---date comparison (Oracle)

Source: Internet
Author: User
Tags time and date

Oracle:

1. Get the current date of the year, month, day, time, minute, second

SelectTo_char (Sysdate,'yyyy') asNowyear fromDual//get the year of the time    SelectTo_char (Sysdate,'mm') asNowmonth fromDual//get the month of the time    SelectTo_char (Sysdate,'DD') asNowday fromDual//get the day of the time    SelectTo_char (Sysdate,'hh24') asNowhour fromDual//when you get the time    SelectTo_char (Sysdate,'mi') asNowminute fromDual//get the minutes of the time   SelectTo_char (Sysdate,'SS') asNowsecond fromDual//gets the seconds of the time
View Code

2. What is the day of the week?

Select to_char (sysdate,'dy'fromselect to_char (to_ Date ('20170725','yyyy/mm/dd'),'day  ' from dual        // results: 2017-07-25

3. Days between two dates (Oracle database Two date subtraction is number of days)

Select Floor (sysdate-to_date ('20170725','yyyy-mm-dd')   from dual; Select to_char (sysdate-to_date ('20170725','yyyy-mm-dd  ' from dual;   // returns the number of days with a decimal point

4. Number of months between two dates

Select Floor (Months_between (sysdate,to_date ('20170725','  Yyyy-mm-dd' from dual;

5. See how many days this year

Select add_months (trunc (sysdate,'year')-Trunc (Sysdate, '  Year '  from dual

6. Set the date language

set nls_date_language=' simpleChinese'set nls_date_language ='American';

Usage of 7.next_day (date,day)

Date represents the day, which represents the week, or 1-7.

Select  from dual;    // Next Thursday

The above is the use of some of Oracle's time and date, should not have installed the relevant software, code is based on some of the information on the Internet written out, has not been verified, so did not write the results, later verification will be added.

MySQL vs Oracle (III)---date comparison (Oracle)

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.