About MySQL using the date manipulation functions date_formate

The basic syntax:
the DATE_FORMAT (DATE, format)
Description: date parameter is legitimate date. format output format predetermined date / time.
Format can be used mainly
Format Description
% a week abbreviated name
% b abbreviated names of months
% c month, the value
% D English prefix with the mid-day
% d day of the month, the value (00-31)
% E month day value (0-31 of)
% F microseconds
% H hour (00-23)
% H hour (01-12)
% the I h (01-12)
% I min value (00-59)
% in J days (001-366)
% K h (0-23)
% h L (1-12)
% m month name
% m month value (00-12)
% P AM or the PM
% R & lt time, 12-hour (hh : mm: ss AM or the PM)
% S seconds (00-59)
% S seconds (00-59)
% T time, 24 hours (HH: mm: SS)
% the U-weeks (00-53) of the week Sunday day
% u weeks (00-53) is the first day of the week Monday
% V weeks (01-53) is the first day of the week Sunday, using the% X
% v weeks (01-53) Monday the first day of the week, and the use of% x
% W week name
% w day of the week (0 = Sunday, 6 = Saturday)
% X-years, which is the first day of the week Sunday, 4, and using the% V
% x in which the periphery is Monday the first day, 4, and use% v
% Y years, 4
,% y, 2
example:

SELECT
DATE_FORMAT(alarm_time, '%Y-%m-%d') AS 'x-x-x',
DATE_FORMAT(alarm_time,'%Y年%m月%d日') AS 'x年x月x日',
DATE_FORMAT(alarm_time, '%m-%d') AS 'x-x',
DATE_FORMAT(alarm_time, '%H时') AS 'x时',
DATE_FORMAT(alarm_time, '%H:%i:%s') AS 'xx:xx'
FROM
grid_alarm_info
WHERE
grid_id = '60089'
1
2
3
4
5
6
7
8
9
10
运行结果

Note: date must be a legitimate date format here is 2019-05-08 16:24:46, wrong format function is invalid for display in different places in different date formats. Format wherein there are many formats, can modify.
Rookie coming out, please correct me!
... forcibly dividing line ...
I could not understand that this thing in the end dim. In the database to get out of date storage time is already standard date format, if only for external display directly to the front-end processing of data throw like, like in the front with a correlation function to format format format you want, and I I want to express the role of this function on the back end. A recent project encountered a problem is to query data for a maximum of one month of the day, such as maximum daily temperatures in May, inventory data, of course, all of this day temperature changes, such as six hours storage time, the day when there are four data records. Simulate what might

tmp represents daily temperature, this time demand the return date and daily maximum temperature, how to deal with it here? (Think
time) .
.
.
.
.
.
.
.
.
.
.
.
.
.

This time the charm for a look at this thing back end.
Use Case

SELECT
DATE_FORMAT(date, '%Y-%m-%d') AS formatDate,
MAX(tmp) AS maxTemp
FROM
temp
WHERE
date LIKE '2019-05%'
GROUP BY formatDate
1
2
3
4
5
6
7
8
运行结果

The end of friends, welcome of all the great God better way to share
--------------------- 

Guess you like

Origin www.cnblogs.com/ly570/p/10987471.html