Oracle database time difference years, months, days, hours, minutes, seconds

Source: Internet
Author: User

1 Declare2 3L_start Date:=To_date ('2015-04-29 01:02:03','YYYY-MM-DD Hh24:mi:ss');4L_end Date:=To_date ('2015-05-15 11:22:33','YYYY-MM-DD Hh24:mi:ss');5 6L_ym interval Year  to Month;7L_ds interval Day  tosecond;8L_year Number;9L_month Number;TenL_day Number; OneL_hour Number; AL_minute Number; -L_second Number; -L_strvarchar2( -); the begin -L_ym:=Numtoyminterval (Trunc (Months_between (L_end, L_start)),'Month'); -L_ds:=Numtodsinterval (l_end- - add_months (L_start, + trunc (Months_between (l_end, L_start )), - ' Day'); +  A SelectExtract Year  fromL_YM), Extract (Month  fromL_ym) at  intoL_year, L_month -  fromdual; -  - SelectExtract Day  froml_ds), -Extract (Hour froml_ds), -Extract (minute froml_ds), inExtract (second fromL_ds) -  intoL_day, L_hour, L_minute, L_second to  fromdual; +  -L_STR:=Lpad (To_char (l_year),4,'0')|| 'years' || theLpad (To_char (L_month),2,'0')|| 'Month' || *Lpad (To_char (L_day),2,'0')|| 'days' || ' ' || $Lpad (To_char (L_hour),2,'0')|| ':' ||Panax NotoginsengLpad (To_char (L_minute),2,'0')|| ':' || -Lpad (To_char (L_second),2,'0'); the  + Dbms_output.put_line (L_STR); A  the End;

Oracle database time difference years, months, days, hours, minutes, seconds

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.