Function: date_format()
Conversion
# 获取前一天时间的最大值 SELECT date_format(CURRENT_DATE()-1, '%Y-%m-%d 23:59:59') # 定义时间值,时间为当前时间整点 SELECT @Front_time := (SELECT CONCAT(CURRENT_DATE(),' ', DATE_FORMAT(now(),'%H'),':00:00')); # 定义时间值,时间为前一小时 SELECT @front_time := (SELECT CONCAT(CURRENT_DATE(),' ', DATE_FORMAT(now(),'%H')-1,':00:00'));
Effect:
##2. Get the current time: year- Month-day hour: minute: second2.1, function now():# 获取格式为当前时间:年-月-日 时:分:秒 SELECT NOW()
Effect:
2.2, function SYSDATE()# 获取格式为当前时间:年-月-日 时:分:秒 SELECT SYSDATE()
Effect:
2.3, function current_timestamp()# 获取格式为当前时间:年-月-日 时:分:秒 SELECT current_timestamp()
Effect:
2.4, Function: localtime()select localtime();
Effect:
2.5. Function: localtimestamp()select localtimestamp();
Effect:
3. Obtain Current time: year-month-day3.1. Function: CURRENT_DATE()SELECT CURRENT_DATE();
Effect:
3.2. Function: CURDATE()SELECT CURDATE();
Effect:
3.3. Function: utc_date()#。**因为我国位于东八时区,所以本地时间 = UTC 时间 + 8 小时** SELECT utc_date(); # utc_date() 年月日 # utc_time() 时分秒 # utc_timestamp() 年月日 时分秒
Effect:
4. Return the time of the last day of this monthFunction: last_day()
select last_day(NOW());
Effect:
The above is the detailed content of What are the ways to get time in mysql. For more information, please follow other related articles on the PHP Chinese website!