Home>Article>Database> What are the ways to get time in mysql

What are the ways to get time in mysql

王林
王林 forward
2023-05-30 22:54:09 1959browse

    1. Get the specified time

    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:

    What are the ways to get time in mysql

    What are the ways to get time in mysql

    What are the ways to get time in mysql

    ##2. Get the current time: year- Month-day hour: minute: second

    2.1, function now():

    # 获取格式为当前时间:年-月-日 时:分:秒 SELECT NOW()

    Effect:

    What are the ways to get time in mysql

    2.2, function SYSDATE()

    # 获取格式为当前时间:年-月-日 时:分:秒 SELECT SYSDATE()

    Effect:

    What are the ways to get time in mysql

    2.3, function current_timestamp()

    # 获取格式为当前时间:年-月-日 时:分:秒 SELECT current_timestamp()

    Effect:

    What are the ways to get time in mysql

    2.4, Function: localtime()

    select localtime();

    Effect:

    What are the ways to get time in mysql

    2.5. Function: localtimestamp()

    select localtimestamp();

    Effect:

    What are the ways to get time in mysql

    3. Obtain Current time: year-month-day

    3.1. Function: CURRENT_DATE()

    SELECT CURRENT_DATE();

    Effect:

    What are the ways to get time in mysql

    3.2. Function: CURDATE()

    SELECT CURDATE();

    Effect:

    What are the ways to get time in mysql

    3.3. Function: utc_date()

    #。**因为我国位于东八时区,所以本地时间 = UTC 时间 + 8 小时** SELECT utc_date(); # utc_date() 年月日 # utc_time() 时分秒 # utc_timestamp() 年月日 时分秒

    Effect:

    What are the ways to get time in mysql

    4. Return the time of the last day of this month

    Function:last_day()

    select last_day(NOW());

    Effect:

    What are the ways to get time in mysql

    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!

    Statement:
    This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete