MySQL gets the current date time (and the time conversion)

Source: Internet
Author: User

Localtimestamp () Localtimestamp
These date-time functions are equivalent to now (). Since the now () function is short and easy to remember, it is recommended that you always use now () instead of the functions listed above.
1.2 Get the current date + time (date + times) function: Sysdate ()
The Sysdate () date-time function is similar to now (), except that it is obtained at the execution start value, and sysdate () dynamically gets the value when the function executes.
Second, MySQL date time Extract (select) function.
Select Extract (microsecond from @dt); --123456
Select Extract (Day_minute from @dt); --100715
The MySQL Extract () function has no function other than date (), Time (), and all other functions one should. And also has the choice ' day_microsecond ' and so on function. Note that this is not just the day and the microsecond, but the part of the date that has been selected to the Microsecond section.
6. MySQL Last_day () function: Returns the last day of the month.
1. MySQL adds a time interval for the date: Date_add ()
+------------------------------------------------+
The Date_add () function adds "1 hours, 15 minutes, 30 seconds" and "1 days, 1 hours, 15 minutes, 30 seconds" for @dt respectively.
Recommendation: Always use the Date_add () date-time function instead of adddate (), Addtime (). <br><br>
The format of the function parameter "P" is "yyyymm" or "yymm", and the second parameter "n" means increment or subtract N month (month).
Select To_days (' 2008-08-08 '); --733627
Select Str_to_date (' 08:09:30 ', '%h:%i:%s '); -08:09:30
Select Get_format (date, ' internal '); --'%y%m%d '
Select Get_format (datetime, ' internal '); --'%y%m%d%h%i%s '
Select Get_format (Time, ' ISO '); --'%h:%i:%s '
V. MySQL timestamp (Timestamp) function
Time zone conversions can also be achieved by Date_add, Date_sub, Timestampadd.
Select Date_add (' 2008-08-08 12:00:00 ', Interval-8 hour); --2008-08-08 04:00:00
Select Timestampadd (Hour,-8, ' 2008-08-08 12:00:00 '); --2008-08-08 04:00:00

MySQL gets the current date time (and the time conversion)

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.