Summary of date/time functions for MySQL and Oracle

Source: Internet
Author: User

Read Catalogue
    • Objective
    • string and date/time reciprocal conversion function
    • Date/Time calculation function
Objective

The date/time of this article is all formatted as "2016-01-01 01:01:01"; monitor_time is the database table field;

string and date/time Mutual conversion function Oracle

Date/Time -to-string function: To_char (t.monitor_time, ' Yyyy-mm-dd hh24:mi:ss ') as Monitortime

string to date/Time function : to_date ("2016-01-01 01:01:01", ' Yyyy-mm-dd hh24:mi:ss ')

Mysql

Date/Time -to-string function: Date_format (t.monitor_time, '%y-%m-%d%h:%i:%s ') as Monitortime

string to date/Time function : Str_to_date ("2016-01-01 01:01:01", '%y-%m-%d%h:%i:%s ')

Date/Time Calculation function Oracle

Add or subtract one hour:

Sysdate+1/24

Sysdate-1/24

Add or subtract one day:

Sysdate+1

Sysdate-1

Increase or decrease January:

Add_months (sysdate, 1)

Add_months (Sysdate,-1)

Increase or decrease the first quarter:

Add_months (Sysdate, 3)

Add_months (Sysdate,-3)

Increase or decrease one year:

Add_months (Sysdate, 12)

Add_months (Sysdate,-12)

Mysql

Add or subtract one hour:

Date_sub (Sysdate (), Interval-1 Hour)

Date_sub (Sysdate (), Interval 1 hour)

Add or subtract one day:

Date_sub (Sysdate (), Interval-1 Day)

Date_sub (Sysdate (), Interval 1 day)

Increase or decrease January:

Date_sub (Sysdate (), Interval-1 month)

Date_sub (Sysdate (), Interval 1 month)

Increase or decrease the first quarter:

Date_sub (Sysdate (), interval-3 month)

Date_sub (Sysdate (), Interval 3 month)

Increase or decrease one year:

Date_sub (Sysdate (), Interval-1 year)

Date_sub (Sysdate (), Interval 1 year)

Summary of date/time functions for MySQL and 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.