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_sub
Usage 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