Oracle date-time timestamp Learning

Source: Internet
Author: User
Tags timestamp to date

1. Obtain the system time Statement (ssxff6 gets the six digits after the decimal point) 

 
Select sysdate, systimestamp, to_char (systimestamp, 'yyyymmdd hh24: MI: ssxff6'), to_char (systimestamp, 'yyyymmdd hh24: MI: Ss. ff6') from dual;

2. Convert string type to Timestamp

 
Select to_timestamp ('2017-09-14 12:52:42. 100', 'syyyy-mm-dd hh24: MI: Ss. ff') from dual;

3. Convert timestamp to date type 

 
Select cast (to_timestamp ('2017-09-14 12:52:42. 100', 'syyyy-mm-dd hh24: MI: Ss. ff') as date) timestamp_to_date from dual;

4. Convert the date type to Timestamp 

Select cast (sysdate as timestamp) date_to_timestamp from dual;

5. The date of two dates is the number of days, while the date of two timestamp is the complete year, month, day, hour, minute, second, decimal second. 

 select sysdate-sysdate, policimestamp-policimestamp from dual; select extract (day from Inter) * 24*60*60 + extract (hour from Inter) * 60*60 + extract (minute from Inter) * 60 + extract (second from Inter) "seconds" from (select to_timestamp ('2017-09-14 12:34:23. 281000000 ', 'yyyy-mm-dd hh24: MI: Ss. FF ')-to_timestamp ('2017-09-14 12:34:22. 984000000 ', 'yyyy-mm-dd hh24: MI: Ss. FF ') Inter from dual); select extract (second from to_timestamp ('2017-09-14 12:34:23. 281000000 ', 'yyyy-mm-dd hh24: MI: Ss. FF ')-extract (second from to_timestamp ('2017-09-14 12:34:22. 984000000 ', 'yyyy-mm-dd hh24: MI: Ss. FF ') from dual; 

 
Note: Therefore, timestamp must calculate the number of seconds between the two dates and use a function to convert them.
The to_char function supports date and timestamp, but trunc does not support the timestamp data type.

Note: This article Reprinted from: http://hulu26.iteye.com/blog/1171749

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.