当前位置:网站首页>Tutorial on principles and applications of database system (054) -- MySQL query (16): usage of date time function
Tutorial on principles and applications of database system (054) -- MySQL query (16): usage of date time function
2022-07-26 01:10:00 【Rsda DBA_ WGX】
Database system principle and Application Tutorial (054)—— MySQL Inquire about ( sixteen ): Usage of date time function
Catalog
- Database system principle and Application Tutorial (054)—— MySQL Inquire about ( sixteen ): Usage of date time function
Using functions when querying can construct more flexible query conditions ,MySQL Provides functions for processing dates and times .
One 、 Create data table
The data table used for query is as follows :
-- Table structure
mysql> desc student;
+--------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+--------------+------+-----+---------+-------+
| s_id | char(5) | NO | PRI | NULL | |
| s_name | char(20) | YES | | NULL | |
| gender | char(1) | YES | | NULL | |
| birth | datetime | YES | | NULL | |
| phone | char(20) | YES | | NULL | |
| addr | varchar(100) | YES | | NULL | |
+--------+--------------+------+-----+---------+-------+
6 rows in set (0.10 sec)
-- Table data
mysql> select * from student;
+-------+-----------+--------+---------------------+-------------+-----------+
| s_id | s_name | gender | birth | phone | addr |
+-------+-----------+--------+---------------------+-------------+-----------+
| S2011 | Zhang Xiaogang | male | 1999-12-03 00:00:00 | 13163735775 | Xinyang City |
| S2012 | Liu Xiaoqing | Woman | 1999-10-11 00:00:00 | 13603732255 | Xinxiang City |
| S2013 | Cao mengde | male | 1998-02-13 00:00:00 | 13853735522 | Zhengzhou city |
| S2014 | Liu Yan | Woman | 1998-06-24 00:00:00 | 13623735335 | Zhengzhou city |
| S2015 | Liu Yan | Woman | 1999-07-06 00:00:00 | 13813735225 | Xinyang City |
| S2016 | Liu Ruofei | Woman | 2000-08-31 00:00:00 | 13683735533 | Kaifeng City |
| S2021 | Dong Wenhua | Woman | 2000-07-30 00:00:00 | 13533735564 | Kaifeng City |
| S2022 | Zhou Huajian | male | 1999-05-25 00:00:00 | 13243735578 | Zhengzhou city |
| S2023 | trump | male | 1999-06-21 00:00:00 | 13343735588 | Xinxiang City |
| S2024 | Obama | male | 2000-10-17 00:00:00 | 13843735885 | Xinyang City |
| S2025 | Zhou Jianhua | male | 2000-08-22 00:00:00 | 13788736655 | Kaifeng City |
| S2026 | Zhang Xueyou | male | 1998-07-06 00:00:00 | 13743735566 | Zhengzhou city |
| S2031 | Lee Myung Bak | Woman | 1999-10-26 00:00:00 | 13643732222 | Zhengzhou city |
| S2032 | Vinci | male | 1999-12-31 00:00:00 | 13043731234 | Zhengzhou city |
+-------+-----------+--------+---------------------+-------------+-----------+
14 rows in set (0.00 sec)
Two 、 Function to query system date and time
Used to return the system date and time of the computer .
The syntax is as follows :
-- Functions take no arguments
-- CURDATE() and CURRENT_DATE() The return values of the two functions are the same , All are the date returned to the system
-- CURTIME() and CURRENT_TIME() The return values of the two functions are the same , Are the return system time
-- function NOW() Return the system date and time .
CURDATE()
CURRENT_DATE()
CURTIME()
CURRENT_TIME()
NOW()
for example :
(1) Query the current date 、 Current time and current date time :
mysql> select current_date(),current_time(),now() from dual;
+----------------+----------------+---------------------+
| current_date() | current_time() | now() |
+----------------+----------------+---------------------+
| 2022-07-23 | 11:33:03 | 2022-07-23 11:33:03 |
+----------------+----------------+---------------------+
1 row in set (0.00 sec)
mysql> select curdate(),curtime(),now() from dual;
+------------+-----------+---------------------+
| curdate() | curtime() | now() |
+------------+-----------+---------------------+
| 2022-07-23 | 11:32:36 | 2022-07-23 11:32:36 |
+------------+-----------+---------------------+
1 row in set (0.00 sec)
(2) Query the student's age
-- Use curdate() function
mysql> select s_id, s_name, year(curdate())-year(birth) age from student where addr=' Xinxiang City ';
+-------+-----------+------+
| s_id | s_name | age |
+-------+-----------+------+
| S2012 | Liu Xiaoqing | 23 |
| S2023 | trump | 23 |
+-------+-----------+------+
2 rows in set (0.00 sec)
-- Use current_date() function
mysql> select s_id, s_name, year(current_date())-year(birth) age from student where addr=' Xinxiang City ';
+-------+-----------+------+
| s_id | s_name | age |
+-------+-----------+------+
| S2012 | Liu Xiaoqing | 23 |
| S2023 | trump | 23 |
+-------+-----------+------+
2 rows in set (0.00 sec)
-- Use now() function
mysql> select s_id, s_name, year(now())-year(birth) age from student where addr=' Xinxiang City ';
+-------+-----------+------+
| s_id | s_name | age |
+-------+-----------+------+
| S2012 | Liu Xiaoqing | 23 |
| S2023 | trump | 23 |
+-------+-----------+------+
2 rows in set (0.01 sec)
3、 ... and 、 Query the various components of the date and time
Return year in date time 、 month 、 Japan 、 when 、 branch 、 second 、 Day of week and other information .
The syntax is as follows :
YEAR(datetime) -- Returns the year in the date , Return value range from 1000 To 9999
MONTH(datetime) -- Return the month in the date , Return value range from 1 To 12
MONTHNAME(datetime) -- Returns the full name of the month in the date
DAY(datetime) -- Returns the day of the current month in the date , Return value range from 1 To 31
DAYOFMONTH(datetime) -- And functions DAY(datetime) The usage is exactly the same
DAYOFWEEK(datetime) -- Returns the day of the week the current date is ( Numerical type :1= Sunday ,2= Monday , ...,7= Saturday )
DAYOFYEAR(datetime) -- Returns the day of the year that the current date is , Return value range from 1 To 366
DAYNAME(datetime) -- Returns the day of the week the current date is ( Character : English words of date )
QUARTER(datetime) -- Returns the quarter in which the current date is , Return value range from 1 To 4
HOUR(datetime) -- Returns the number of hours of the current time , Return value range from 0 To 23
MINUTE(datetime) -- Returns the number of minutes of the current time , Return value range from 0 To 59
SECOND(datetime) -- Returns the number of seconds of the current time , Return value range from 0 To 59
-- EXTRACT Function USES part The parameter indicates which part of the date and time to return , namely : year 、 month 、 Japan 、 when 、 branch 、 second 、 Day of week and other information
-- part The values of parameters are as follows :YEAR( year )、MONTH( month )、DAY( Japan )、HOUR( when )、MINUTE( branch )、SECOND( second )
-- MICROSECOND( millisecond )、WEEK( The weeks of the year )、QUARTER( What quarter )
EXTRACT(part from datetime)
for example :
(1) Examples of basic usage
-- Return the year in the date respectively 、 month 、 Japan
mysql> select year(now()),month(now()),day(now()) from dual;
+-------------+--------------+------------+
| year(now()) | month(now()) | day(now()) |
+-------------+--------------+------------+
| 2022 | 7 | 23 |
+-------------+--------------+------------+
1 row in set (0.00 sec)
mysql> select EXTRACT(year from now()),EXTRACT(month from now()),EXTRACT(day from now())
from dual;
+--------------------------+---------------------------+-------------------------+
| EXTRACT(year from now()) | EXTRACT(month from now()) | EXTRACT(day from now()) |
+--------------------------+---------------------------+-------------------------+
| 2022 | 7 | 23 |
+--------------------------+---------------------------+-------------------------+
1 row in set (0.00 sec)
-- Respectively return the hours in time 、 branch 、 second
mysql> select hour(now()),minute(now()),second(now()) from dual;
+-------------+---------------+---------------+
| hour(now()) | minute(now()) | second(now()) |
+-------------+---------------+---------------+
| 11 | 45 | 29 |
+-------------+---------------+---------------+
1 row in set (0.00 sec)
mysql> select EXTRACT(hour from now()),EXTRACT(minute from now()),EXTRACT(second from now())
from dual;
+--------------------------+----------------------------+----------------------------+
| EXTRACT(hour from now()) | EXTRACT(minute from now()) | EXTRACT(second from now()) |
+--------------------------+----------------------------+----------------------------+
| 11 | 57 | 34 |
+--------------------------+----------------------------+----------------------------+
1 row in set (0.00 sec)
-- Query the year in the current date 、 month 、 Japan 、 What day
mysql> select year(now()),monthname(now()),dayofmonth(now()),dayofweek(now()),dayname(now())
-> from dual;
+-------------+------------------+-------------------+------------------+----------------+
| year(now()) | monthname(now()) | dayofmonth(now()) | dayofweek(now()) | dayname(now()) |
+-------------+------------------+-------------------+------------------+----------------+
| 2022 | July | 23 | 7 | Saturday |
+-------------+------------------+-------------------+------------------+----------------+
1 row in set (0.02 sec)
-- The current date of query is the day of the year , What quarter
mysql> select dayofyear(now()),quarter(now()) from dual;
+------------------+----------------+
| dayofyear(now()) | quarter(now()) |
+------------------+----------------+
| 204 | 3 |
+------------------+----------------+
1 row in set (0.00 sec)
mysql> select EXTRACT(quarter from now()) from dual;
+-----------------------------+
| EXTRACT(quarter from now()) |
+-----------------------------+
| 3 |
+-----------------------------+
1 row in set (0.00 sec)
(2) Query the information of students born in the third quarter
mysql> select * from student where quarter(birth)=3;
+-------+-----------+--------+---------------------+-------------+-----------+
| s_id | s_name | gender | birth | phone | addr |
+-------+-----------+--------+---------------------+-------------+-----------+
| S2015 | Liu Yan | Woman | 1999-07-06 00:00:00 | 13813735225 | Xinyang City |
| S2016 | Liu Ruofei | Woman | 2000-08-31 00:00:00 | 13683735533 | Kaifeng City |
| S2021 | Dong Wenhua | Woman | 2000-07-30 00:00:00 | 13533735564 | Kaifeng City |
| S2025 | Zhou Jianhua | male | 2000-08-22 00:00:00 | 13788736655 | Kaifeng City |
| S2026 | Zhang Xueyou | male | 1998-07-06 00:00:00 | 13743735566 | Zhengzhou city |
+-------+-----------+--------+---------------------+-------------+-----------+
5 rows in set (0.00 sec)
(3) Check the information of students whose birthdays are this month
mysql> select * from student where month(birth)=month(now());
+-------+-----------+--------+---------------------+-------------+-----------+
| s_id | s_name | gender | birth | phone | addr |
+-------+-----------+--------+---------------------+-------------+-----------+
| S2015 | Liu Yan | Woman | 1999-07-06 00:00:00 | 13813735225 | Xinyang City |
| S2021 | Dong Wenhua | Woman | 2000-07-30 00:00:00 | 13533735564 | Kaifeng City |
| S2026 | Zhang Xueyou | male | 1998-07-06 00:00:00 | 13743735566 | Zhengzhou city |
+-------+-----------+--------+---------------------+-------------+-----------+
3 rows in set (0.00 sec)
(4) Check the student information of today's birthday
mysql> select * from student
where month(birth)=month(now()) and day(birth)=day(now());
Empty set (0.00 sec)
Four 、 A function that calculates the date and time
1、DATE_ADD() function
Add a date to a date time 、 Time unit .
The syntax is as follows :
-- unit: date 、 Time unit , The value is :YEAR( year ),MONTH( month ),DAY( God ),HOUR( Hours ),MINUTE( minute ),
-- SECOND( second ),WEEK( week ),QUARTER( quarter )
-- n: It's an integer . When n Greater than 0 when , Said to increase n Date time units , When n Less than 0 when , To reduce n Time units
DATE_ADD(datetime, interval n unit)
for example :
(1) Examples of basic usage
-- Query after the current date 2 year 、10 Months 、258 The date of day
/* select now(), date_add(now(),interval 2 year) date1, date_add(now(),interval 10 month) date2, date_add(now(),interval 258 day) date3 from dual; */
mysql> select now(),
-> date_add(now(),interval 2 year) date1,
-> date_add(now(),interval 10 month) date2,
-> date_add(now(),interval 258 day) date3
-> from dual;
+---------------------+---------------------+---------------------+---------------------+
| now() | date1 | date2 | date3 |
+---------------------+---------------------+---------------------+---------------------+
| 2022-07-23 12:07:41 | 2024-07-23 12:07:41 | 2023-05-23 12:07:41 | 2023-04-07 12:07:41 |
+---------------------+---------------------+---------------------+---------------------+
1 row in set (0.00 sec)
-- Query before the current date 3 year 、20 Months 、558 The date of day
/* select now(), date_add(now(),interval -3 year) date1, date_add(now(),interval -20 month) date2, date_add(now(),interval -558 day) date3 from dual; */
mysql> select now(),
-> date_add(now(),interval -3 year) date1,
-> date_add(now(),interval -20 month) date2,
-> date_add(now(),interval -558 day) date3
-> from dual;
+---------------------+---------------------+---------------------+---------------------+
| now() | date1 | date2 | date3 |
+---------------------+---------------------+---------------------+---------------------+
| 2022-07-23 12:09:13 | 2019-07-23 12:09:13 | 2020-11-23 12:09:13 | 2021-01-11 12:09:13 |
+---------------------+---------------------+---------------------+---------------------+
1 row in set (0.01 sec)
-- Query after the current date 12 Zhou 、5 Date of quarter
/* select now(), date_add(now(),interval 12 week) date1, date_add(now(),interval 5 quarter) date2 from dual; */
mysql> select now(),
-> date_add(now(),interval 12 week) date1,
-> date_add(now(),interval 5 quarter) date2
-> from dual;
+---------------------+---------------------+---------------------+
| now() | date1 | date2 |
+---------------------+---------------------+---------------------+
| 2022-07-23 12:14:37 | 2022-10-15 12:14:37 | 2023-10-23 12:14:37 |
+---------------------+---------------------+---------------------+
1 row in set (0.00 sec)
-- After querying the current time 2 Hours 、125 minute 、258 The second time
/* select now(), date_add(now(),interval 2 hour) time1, date_add(now(),interval 125 minute) time2, date_add(now(),interval 258 second) time3 from dual; */
mysql> select now(),
-> date_add(now(),interval 2 hour) time1,
-> date_add(now(),interval 125 minute) time2,
-> date_add(now(),interval 258 second) time3
-> from dual;
+---------------------+---------------------+---------------------+---------------------+
| now() | time1 | time2 | time3 |
+---------------------+---------------------+---------------------+---------------------+
| 2022-07-23 12:13:02 | 2022-07-23 14:13:02 | 2022-07-23 14:18:02 | 2022-07-23 12:17:20 |
+---------------------+---------------------+---------------------+---------------------+
1 row in set (0.00 sec)
(2) Inquire about 20 Students who celebrate their birthday days later
/* select * from student where month(birth) = date_add(now(),interval 20 day) and day(birth) = date_add(now(),interval 20 day); */
mysql>
mysql> select * from student
-> where month(birth) = date_add(now(),interval 20 day) and
-> day(birth) = date_add(now(),interval 20 day);
Empty set (0.01 sec)
2、ADDDATE() function
ADDDATE() Function and DATE_ADD() Functions are similar .
The syntax is as follows :
ADDDATE(datetime,days) -- increase (n>0) Or reduce (n<0) n God
ADDDATE(datetime,interval n unit) -- Usage and DATE_ADD() The function is exactly the same
for example :
mysql> select now(),adddate(now(),100),adddate(now(),-100) from dual;
+---------------------+---------------------+---------------------+
| now() | adddate(now(),100) | adddate(now(),-100) |
+---------------------+---------------------+---------------------+
| 2022-07-23 12:19:52 | 2022-10-31 12:19:52 | 2022-04-14 12:19:52 |
+---------------------+---------------------+---------------------+
1 row in set (0.00 sec)
3、DATEDIFF() function
Returns the number of days between two dates .
The syntax is as follows :
-- Returns the number of days between two dates
DATEDIFF(datetime1,datetime2)
for example : Query the student's age
mysql> select s_id, s_name, birth, datediff(now(),birth)/365 age from student;
+-------+-----------+---------------------+---------+
| s_id | s_name | birth | age |
+-------+-----------+---------------------+---------+
| S2011 | Zhang Xiaogang | 1999-12-03 00:00:00 | 22.6521 |
| S2012 | Liu Xiaoqing | 1999-10-11 00:00:00 | 22.7973 |
| S2013 | Cao mengde | 1998-02-13 00:00:00 | 24.4548 |
| S2014 | Liu Yan | 1998-06-24 00:00:00 | 24.0959 |
| S2015 | Liu Yan | 1999-07-06 00:00:00 | 23.0630 |
| S2016 | Liu Ruofei | 2000-08-31 00:00:00 | 21.9068 |
| S2021 | Dong Wenhua | 2000-07-30 00:00:00 | 21.9945 |
| S2022 | Zhou Huajian | 1999-05-25 00:00:00 | 23.1781 |
| S2023 | trump | 1999-06-21 00:00:00 | 23.1041 |
| S2024 | Obama | 2000-10-17 00:00:00 | 21.7781 |
| S2025 | Zhou Jianhua | 2000-08-22 00:00:00 | 21.9315 |
| S2026 | Zhang Xueyou | 1998-07-06 00:00:00 | 24.0630 |
| S2031 | Lee Myung Bak | 1999-10-26 00:00:00 | 22.7562 |
| S2032 | Vinci | 1999-12-31 00:00:00 | 22.5753 |
+-------+-----------+---------------------+---------+
14 rows in set (0.00 sec)
4、TIMEDIFF() function
Returns the interval between two times .
The syntax is as follows :
-- Returns the interval between two times
TIMEDIFF(datetime1, datetime2)
for example :
/* SET @time1 = '2022-7-23 18:23:15'; SET @time2 = '2022-7-22 18:23:15'; SET @time3 = '2022-5-29 18:23:15'; SELECT TIMEDIFF(NOW(),@time1),TIMEDIFF(NOW(),@time2),TIMEDIFF(NOW(),@time3) from dual; */
mysql> SET @time1 = '2022-7-23 18:23:15';
Query OK, 0 rows affected (0.01 sec)
mysql> SET @time2 = '2022-7-22 18:23:15';
Query OK, 0 rows affected (0.00 sec)
mysql> SET @time3 = '2022-5-29 18:23:15';
Query OK, 0 rows affected (0.00 sec)
mysql> SELECT TIMEDIFF(NOW(),@time1),TIMEDIFF(NOW(),@time2),TIMEDIFF(NOW(),@time3)
-> from dual;
+------------------------+------------------------+------------------------+
| TIMEDIFF(NOW(),@time1) | TIMEDIFF(NOW(),@time2) | TIMEDIFF(NOW(),@time3) |
+------------------------+------------------------+------------------------+
| 00:18:26 | 24:18:26 | 838:59:59 |
+------------------------+------------------------+------------------------+
1 row in set, 1 warning (0.00 sec)
5、 ... and 、 Other functions
1、DATE() and TIME() function
Returns the date and time in a date time expression .
The syntax is as follows :
DATE(datetime) -- Returns the date in the datetime expression
TIME(datetime) -- Returns the time in the date time expression
for example :
mysql> select now(),date(now()),time(now()) from dual;
+---------------------+-------------+-------------+
| now() | date(now()) | time(now()) |
+---------------------+-------------+-------------+
| 2022-07-23 18:55:18 | 2022-07-23 | 18:55:18 |
+---------------------+-------------+-------------+
1 row in set (0.00 sec)
2、MAKEDATE() And MAKETIME() function
Generate the date and time according to the specified parameters .
The syntax is as follows :
-- The first parameter represents the year , The second parameter represents the number of days
-- The return value of the function indicates from the specified year 1 month 1 The day begins ,n Days after
MAKEDATE(year,n)
MAKETIME(hour,minute,second) -- According to the parameters provided 、 branch 、 Seconds generate a time
for example :
mysql> select makedate(2022,152),makedate(2022,365),makedate(2022,455) from dual;
+--------------------+--------------------+--------------------+
| makedate(2022,152) | makedate(2022,365) | makedate(2022,455) |
+--------------------+--------------------+--------------------+
| 2022-06-01 | 2022-12-31 | 2023-03-31 |
+--------------------+--------------------+--------------------+
1 row in set (0.00 sec)
mysql> select maketime(22,15,33) from dual;
+--------------------+
| maketime(22,15,33) |
+--------------------+
| 22:15:33 |
+--------------------+
1 row in set (0.00 sec)
3、LAST_DAY() function
Returns the date of the last day of the month in which the date expression is located .
The syntax is as follows :
LAST_DAY(datetime)
for example :
mysql> select NOW(),LAST_DAY(NOW()),LAST_DAY('2022-2-5'),LAST_DAY('2020-2-5')
from dual\G
*************************** 1. row ***************************
NOW(): 2022-07-23 19:06:33
LAST_DAY(NOW()): 2022-07-31
LAST_DAY('2022-2-5'): 2022-02-28
LAST_DAY('2020-2-5'): 2020-02-29
1 row in set (0.00 sec)
4、DATE_FORMAT() function
Format a date .
The syntax is as follows :
DATE_FORMAT(datetime, format)
/* -- according to format Display the date in the format specified by the string . -- format The characters used in the string are as follows : %a The abbreviated name of a weekday (Sun … Sat) %b Abbreviated name of the month (Jan … Dec) %c month , Digital form (0 … 12) %D Date of the month with English suffix (0th, 1st, 2nd, 3rd, …) %d Date of the month , Digital form (00 … 31) %e Date of the month , Digital form (0 … 31) %f Microsecond (000000 … 999999) %H Hours (00 … 23) %h Hours (01 … 12) %I minute (0 … 59) %i minute , Digital form (00 … 59) %j Days of the year (001 … 366) %k Hours (0 … 23) %l Hours (1 … 12) %M The name of the month (January … December) %m month , Digital form (00 … 12) %p In the morning (AM) Or afternoon ( PM) %r Time , 12 hourly ( Hours hh: minute mm: Number of seconds ss After add AM or PM) %S second (00 … 59) %s second (00 … 59) %T Time ,24 hourly ( Hours hh: minute mm: Number of seconds ss) %U Zhou (00 … 53), Sunday is the first day of the week %u Zhou (00 … 53), Monday is the first day of the week %V Zhou (01 … 53), Sunday is the first day of the week ; and %X Use at the same time %v Zhou (01 … 53), Monday is the first day of the week ; and %x Use at the same time %W Weekday name ( Sunday … Saturday ) %w Every day of the week (0= Sunday … 6= Saturday ) %X The year of the week , Sunday is the first day of the week , Digital form ,4 digit ; and %V Use at the same time %x The year of the week , Monday is the first day of the week , Digital form ,4 digit ; and %v Use at the same time %Y year , Digital form ,4 digit %y year , Digital form (2 digit ) %% ‘%’ Characters */
for example :
(1) With 【M%D%,Y%】 Format display birth
mysql> select s_id, s_name, date_format(birth,'%M %d,%Y') birth from student;
+-------+-----------+------------------+
| s_id | s_name | birth |
+-------+-----------+------------------+
| S2011 | Zhang Xiaogang | December 03,1999 |
| S2012 | Liu Xiaoqing | October 11,1999 |
| S2013 | Cao mengde | February 13,1998 |
| S2014 | Liu Yan | June 24,1998 |
| S2015 | Liu Yan | July 06,1999 |
| S2016 | Liu Ruofei | August 31,2000 |
| S2021 | Dong Wenhua | July 30,2000 |
| S2022 | Zhou Huajian | May 25,1999 |
| S2023 | trump | June 21,1999 |
| S2024 | Obama | October 17,2000 |
| S2025 | Zhou Jianhua | August 22,2000 |
| S2026 | Zhang Xueyou | July 06,1998 |
| S2031 | Lee Myung Bak | October 26,1999 |
| S2032 | Vinci | December 31,1999 |
+-------+-----------+------------------+
14 rows in set (0.00 sec)
(2) With 【%M %e,%Y】 Format display birth
mysql> select s_id, s_name, date_format(birth,'%M %e,%Y') birth from student;
+-------+-----------+------------------+
| s_id | s_name | birth |
+-------+-----------+------------------+
| S2011 | Zhang Xiaogang | December 3,1999 |
| S2012 | Liu Xiaoqing | October 11,1999 |
| S2013 | Cao mengde | February 13,1998 |
| S2014 | Liu Yan | June 24,1998 |
| S2015 | Liu Yan | July 6,1999 |
| S2016 | Liu Ruofei | August 31,2000 |
| S2021 | Dong Wenhua | July 30,2000 |
| S2022 | Zhou Huajian | May 25,1999 |
| S2023 | trump | June 21,1999 |
| S2024 | Obama | October 17,2000 |
| S2025 | Zhou Jianhua | August 22,2000 |
| S2026 | Zhang Xueyou | July 6,1998 |
| S2031 | Lee Myung Bak | October 26,1999 |
| S2032 | Vinci | December 31,1999 |
+-------+-----------+------------------+
14 rows in set (0.00 sec)
(3) With 【%M %D,%Y】 Format display birth
mysql> select s_id, s_name, date_format(birth,'%M %D,%Y') birth from student;
+-------+-----------+--------------------+
| s_id | s_name | birth |
+-------+-----------+--------------------+
| S2011 | Zhang Xiaogang | December 3rd,1999 |
| S2012 | Liu Xiaoqing | October 11th,1999 |
| S2013 | Cao mengde | February 13th,1998 |
| S2014 | Liu Yan | June 24th,1998 |
| S2015 | Liu Yan | July 6th,1999 |
| S2016 | Liu Ruofei | August 31st,2000 |
| S2021 | Dong Wenhua | July 30th,2000 |
| S2022 | Zhou Huajian | May 25th,1999 |
| S2023 | trump | June 21st,1999 |
| S2024 | Obama | October 17th,2000 |
| S2025 | Zhou Jianhua | August 22nd,2000 |
| S2026 | Zhang Xueyou | July 6th,1998 |
| S2031 | Lee Myung Bak | October 26th,1999 |
| S2032 | Vinci | December 31st,1999 |
+-------+-----------+--------------------+
14 rows in set (0.00 sec)
(4) With 【%a,%M %D,%Y】 The format shows the issue date of the stock
mysql> select s_id, s_name, date_format(birth,'%a, %M %D,%Y') birth from student;
+-------+-----------+-------------------------+
| s_id | s_name | birth |
+-------+-----------+-------------------------+
| S2011 | Zhang Xiaogang | Fri, December 3rd,1999 |
| S2012 | Liu Xiaoqing | Mon, October 11th,1999 |
| S2013 | Cao mengde | Fri, February 13th,1998 |
| S2014 | Liu Yan | Wed, June 24th,1998 |
| S2015 | Liu Yan | Tue, July 6th,1999 |
| S2016 | Liu Ruofei | Thu, August 31st,2000 |
| S2021 | Dong Wenhua | Sun, July 30th,2000 |
| S2022 | Zhou Huajian | Tue, May 25th,1999 |
| S2023 | trump | Mon, June 21st,1999 |
| S2024 | Obama | Tue, October 17th,2000 |
| S2025 | Zhou Jianhua | Tue, August 22nd,2000 |
| S2026 | Zhang Xueyou | Mon, July 6th,1998 |
| S2031 | Lee Myung Bak | Tue, October 26th,1999 |
| S2032 | Vinci | Fri, December 31st,1999 |
+-------+-----------+-------------------------+
14 rows in set (0.01 sec)
边栏推荐
- [laser principle and application-4]: internal structure and working principle of laser
- Talk about "people" in the R & D team
- Redis数据结构详解,结合书本
- NLP introduction + practice: Chapter 4: using pytorch to manually realize linear regression
- Spine_ Adnexal skin
- 链表相关面试题
- Game thinking 17: Road finding engine recast and detour learning II: recast navigation grid generation process and limitations
- Unity get the animation being played
- 嵌入式开发:技巧和窍门——设计强大的引导加载程序的7个技巧
- 【RTOS训练营】继续程序框架、tick中断补充、预习、课后作业和晚课提问
猜你喜欢

RHCE之at和crontab命令详解及chrony部署

【RTOS训练营】环形缓冲区、AT指令、预习安排和晚课提问

# 浏览器开发使用技巧

Talk about "people" in the R & D team

Lock upgrade: no lock, bias lock, lightweight lock, heavyweight lock

Travel + strategy accelerated landing, jietu new product matrix exposure
![[RTOS training camp] program framework, preview, after-school homework and evening class questions](/img/ce/ae35acf14519f6856ba2d181ee7201.jpg)
[RTOS training camp] program framework, preview, after-school homework and evening class questions

Jupyter changes the main interface and imports the dataset

Tencent employees' salary: the real 985 graduation salary, do you think I can be saved? Netizen: daily salary?
![[RTOS training camp] I2C and UART knowledge and preview arrangement + evening class questions](/img/4c/3c0453caaa4e7e8ce64da8ff3be93b.jpg)
[RTOS training camp] I2C and UART knowledge and preview arrangement + evening class questions
随机推荐
Spine_附件皮肤
Jupyter changes the main interface and imports the dataset
Force buckle 25. Turn over the linked list in a group of K
链表相关面试题
【RTOS训练营】环形缓冲区、AT指令、预习安排和晚课提问
数据库系统原理与应用教程(054)—— MySQL 查询(十六):日期时间型函数的用法
"Introduction to natural language processing practice" deep learning foundation - attention mechanism, transformer deep analysis and learning material summary
换ip软件的用途很广及原理 动态IP更换的四种方法来保护网络隐私
How accurate is the IP address? What are dynamic IP and static IP? The most common method of switching IP
【RTOS训练营】晚课学员问题
Timeout settings for feign and hystrix
Unity get the animation being played
Set set learning
[software development specification II] prohibited item development specification
全国一半人跑长沙,长沙一半人跑哪?
Detailed explanation of at and crontab commands of RHCE and deployment of Chrony
1.30 升级bin文件添加后缀及文件长度
Half of the people in the country run in Changsha. Where do half of the people in Changsha run?
[RTOS training camp] review of the previous section, idle tasks, timer tasks, execution sequence, scheduling strategy and evening class questions
游戏思考17:寻路引擎recast和detour学习二:recast导航网格生成流程及局限性