Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the ways to get time in mysql

Shulou Source: shulou.com Published: 2022-06-01 04:43:26 09月17日 Update

This article will explain in detail the ways to obtain time in mysql. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

1. Get the specified time

Function: date_format () conversion

# get the maximum value of the previous day's time SELECT date_format (CURRENT_DATE ()-1,'% Y-%m-%d 23 Y-%m-%d 59 Front_time 59') # define the time value, which is the current time on the hour SELECT @ time: = (SELECT CONCAT (CURRENT_DATE (),'', DATE_FORMAT (now (),'% H'),': 00VAN00')) # define the time value, which is SELECT @ front_time: = (SELECT CONCAT (CURRENT_DATE (),'', DATE_FORMAT (now (),'% H')-1))

Effect:

2. Get the current time: year-month-day hour: minute 2.1.Function now (): # get the format as current time: year-month-day hour: minute: second SELECT NOW ()

Effect:

2.2.2.The function SYSDATE () # is in the format of current time: year-month-day hour: minute: second SELECT SYSDATE ()

Effect:

2.3.The function current_timestamp () # is in the format of current time: year-month-day hour: minute: second SELECT current_timestamp ()

Effect:

Function: localtime () select localtime ()

Effect:

Function: localtimestamp () select localtimestamp ()

Effect:

3. Get the current time: year-month-day 3.1. Function: CURRENT_DATE () SELECT CURRENT_DATE ()

Effect:

Function: CURDATE () SELECT CURDATE ()

Effect:

Function: utc_date () #. * * because our country is located in the East eight time zone, local time = UTC time + 8 hours * * SELECT utc_date (); # utc_date () # utc_time () hours # utc_timestamp ()

Effect:

4. Return to the last day of the month

Function: last_day ()

Select last_day (NOW ())

Effect:

This is the end of this article on "what are the ways to obtain time in mysql?". I hope the above content can be helpful to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Time function effect format article method hour year month day time more good practical maximum content time China hour article time zone Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MySQL Redmi Shulou Technology Microsoft