MySQL Time function

Source: Internet
Author: User
Tags current time

Reprint please indicate source: http://blog.csdn.net/zhaoyanjun6/article/details/80393761
This article is from "Zhaoyan's blog"

Get current time
    • Return current Date: select Curdate ();
2018-05-21
    • Return current time: select Curtime ();
16:24:03
    • Returns the current date and time: select Now ();
2018-05-21 16:24:03
    • Returns the current date and time: Select Now () + 0;
//2018年05月21日,16点38分03秒20180521163803
    • Returns the current date and time: Select Now (3);

Now (3): Seconds of precision, accurate to seconds after decimal 3 bits

//2018年05月21日,16点41分50.870秒2018-05-21 16:41:50.870
    • Returns Date: Select Year (now ());
2018
    • Returns date Month: Select month ("2018-05-21 16:29");
5
    • Returns the name of the date month: Select MonthName ("2018-05-21 16:29");
May
    • The return date is the week ordinal of the Year: Select Week (now ());
20
    • Returns the time value: Select Hour ("2018-05-21 16:29");
16
    • Returns the time value: Select minute ("2018-05-21 16:29");
29
    • Returns the quarter of time, 1--4:select quarter (now ());

There are 4 quarters a year

2
Time change time increased: Date_add ()
    • 1. Add 3 days to the current time
select date_add(now(), interval 3 day) ;   //在当前时间上增加 3 天select date_add(now(), interval -3 day) ;  //在当前时间上减少 3 天select date_add(now(), interval 1 hour);  //在当前时间上增加 1 小时select date_add(now(), interval 1 minute);  //在当前时间上增加 1 分钟select date_add(now(), interval 1 second);  //在当前时间上增加 1 秒select date_add(now(), interval 1 microsecond); //在当前时间上增加 1 微秒select date_add(now(), interval 1 week);   //在当前时间上增加 1 星期select date_add(now(), interval 1 month);   //在当前时间上增加 1 个月select date_add(now(), interval 1 quarter);  //在当前时间上增加 1 个季度,相当于3个月select date_add(now(), interval 1 year);  //在当前时间上增加 1 年
Time reduction: Date_sub ()

date_subUsage and date_add consistency, no longer examples here.

Time Difference DateDiff ()
Time formatting
select date_format("2018-05-10","%Y/%m/%d")

Results

2018/05/10

Personal number: zhaoyanjun125, welcome attention

MySQL Time function

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.