MySQL date and time usage instructions

Source: Internet
Author: User

In the maintenance process, we are more tangled in the format of the Time field, I combed today, MySQL other common syntax and oralce basic similar (including comments and so on with the same as Oracle), the difference is the same date type.

The time format that MySQL can often use
Date (Time field) equals Oracle To_date (sysdate, ' yyyy-mm-dd ') accurate to day
Date_format (sysdate, '%y-%m-%d%h:%i:%s ') equals to_date (Sysdate, ' Yyyy-mm-dd hh24:mi:ss ') custom format here is accurate to the second, can be tailored to specific circumstances such as Date_ FORMAT (sysdate, '%y-%m-%d%H ') is accurate to the hour.
Now (); --Get the current month day and minute "Equals Oracle Yyyy-mm-dd HH24:MI:SS"; Show results: 2018-04-04 14:18:18
Curdate (); --Get the current month day "equals to Oracle YYYY-MM-DD"; Show results: 2018-04-04
Curtime (); --Gets the current time and seconds "equals Oracle HH24:MI:SS"; Display Result: 14:18:40
Now (), Curdate (), Curtime (); --Get the current day of the month and minute 2018-04-04 14:18:47 2018-04-04 14:18:47
Utc_timestamp (), Utc_date (), Utc_time (); --Get the 0 time zone of the current month and time of day and minute 2018-04-04 06:19:07 2018-04-04 06:19:07
Timestamp (now (), ' -00:30:00 ');---current time 30 minutes ago
Summarize MySQL functions for time

Also: MySQL is annotated like Oracle.

Example:
SELECT * from Tneticket a where date_format (Dtrtime, ' Yyyy-mm-dd hh:mi ') > ' 2018-04-04 10:00 ';

SELECT * from Exception_msg a where a.sts= ' F ' and date (a.appl_date) = ' 2018-04-04 ' and a.err_msg like ' String index out of R Ange:-1 ';
SELECT * from UIQ a where a.rel_object_id= ' 1804040398736999 ';
SELECT * from UIQ a where/*a.rel_object_id= ' 1804040398736999 ' and*/a.req_data like '%<operara>000000000000000 </operara>% ';
Select COUNT (1) from exception_msg s where s.appl_date> timestamp (now (), ' -00:30:00 ') and s.sts= ' F ';

Select Date_format (a.dtrtime, '%y-%m-%d%h:%i '), a.* from Tneticket a where date_format (Dtrtime, '%y-%m-%d%h:%i:%s ') > ' 2018-04-04 10:00:00 ' and Date_format (Dtrtime, '%y-%m-%d%h:%i:%s ') <= ' 2018-04-04 15:00:00 ';
Patrol number: ' 13141101344 ', ' 15611088088 '

MySQL date and time usage instructions

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.