What are the ways to get time in mysql

王林
Release: 2023-05-30 22:54:09
forward
1944 people have browsed it

    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'));
    Copy after login

    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()
    Copy after login

    Effect:

    What are the ways to get time in mysql

    2.2, function SYSDATE()

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

    Effect:

    What are the ways to get time in mysql

    2.3, function current_timestamp()

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

    Effect:

    What are the ways to get time in mysql

    2.4, Function: localtime()

    select localtime();
    Copy after login

    Effect:

    What are the ways to get time in mysql

    2.5. Function: localtimestamp()

    select localtimestamp();
    Copy after login

    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();
    Copy after login

    Effect:

    What are the ways to get time in mysql

    3.2. Function: CURDATE()

    SELECT CURDATE();
    Copy after login

    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() 年月日 时分秒
    Copy after login

    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());
    Copy after login

    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!

    Related labels:
    source:yisu.com
    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!