Oracle Date Calculation

Source: Internet
Author: User
Tags truncated

Oracle queries the month for how many days, the code is as follows:

Select To_number (Add_months (trunc (' 2014-11-4 11:13:53 ', ' yyyy-mm-dd hh24:mi:ss '), ' mm '), 1)-Trunc (' To_date (' 2014-11-4 11:13:53 ', ' yyyy-mm-dd hh24:mi:ss '), ' mm ')) Daycountfrom dual;select to_number (add_months (trunc (to_  Date (To_char (sysdate, ' yyyy-mm-dd hh24:mi:ss '), ' Yyyy-mm-dd hh24:mi:ss '), ' mm '), 1)-Trunc (To_date (To_char (   Sysdate, ' Yyyy-mm-dd hh24:mi:ss '), ' Yyyy-mm-dd hh24:mi:ss '), ' mm ') Dayscount from  dual

Oracle queries the last day of the month with the following code:

Select To_char (Trunc (Add_months (Last_day (Sysdate),-1) + 1), ' yyyy-mm-dd ') "The first day of the Month", To_char (Last_day (sysdate), ' Yyyy-mm-dd ') "Last day of the month" from  dual;


Attached: Oracle Date operation:

--oracle trunc () function usage/************** date ********************/1.select trunc (sysdate) from dual--2011-3-18 Today's date is 2011-3-18 2.select trunc (sysdate, ' mm ') from dual--2011-3-1 returns the first day of the month. 3.select trunc (sysdate, ' yy ') from dual--2011-1-1 returns the first day of the year 4.select trunc (sysdate, ' DD ') from dual--2011-3-18 return Current Month day 5.select trunc (sysdate, ' yyyy ') from dual--2011-1-1 return the first day of the year 6.select trunc (sysdate, ' d ') from dual--2011-3-13 (star Days) returns the first day of the current week 7.select trunc (sysdate, ' hh ') from dual--2011-3-18 14:00:00 current time is 14:41 8.select trunc (sysdate, ' mi ') The From dual--2011-3-18 14:41:00 TRUNC () function does not have a precise/*************** number ********************//* TRUNC (number,num_digits) num The BER requires the number of truncated rounding. The num_digits is used to specify the number of rounding precision. The default value for Num_digits is 0. TRUNC () function is not rounded when truncated/9.select TRUNC (123.458) from dual--123 10.select TRUNC (123.458,0) from dual--123 11.select TRUNC ( 123.458,1) from dual--123.4 12.select trunc (123.458,-1) from dual--120 13.select trunc (123.458,-4) from dual--0 14.sele CT trunc (123.458,4) From dual--123.458 15.select trunc (123) from dual--123 16.select trunc (123,1) from dual--123 17.select trunc (123,-1) From dual--120



Oracle Date Calculation

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.