Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

An example of using the MySQL date function

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly shows you the "example of the use of MySQL date function", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "the use of MySQL date function example" this article.

Date function

1. CURDATE () / CURRENT_DATE () returns the current date

SELECT CURDATE (); SELECT CURRENT_DATE ();-return 2019-02-19

2. CURRENT_TIME () / CURTIME () returns the current time

SELECT CURRENT_TIME ();-returns 11:40:45

3. CURRENT_TIMESTAMP () returns the current date and time

SELECT CURRENT_TIMESTAMP ();-return 2019-02-19 11:41:32

4. ADDDATE (dline n) calculates the start date d plus the date of n days

SELECT ADDDATE ("2017-06-15", INTERVAL 10 DAY);-return 2017-06-25

5. ADDTIME (t) time t plus n seconds time

SELECT ADDTIME ('2011-11-11-11-11-11-11-11-11-11-11-11 11:11:16

6. DATE () extracts the date value from the date or date-time expression

SELECT DATE ("2017-06-15 11:11:16");-return 2017-06-15

7. DAY (d) returns the date part of the date value d

SELECT DAY ("2017-06-15");-return 15

8. DATEDIFF (D1 and D2) calculates the number of days between D1 and D2

SELECT DATEDIFF ('2001-01-01-01); return-32

9. DATE_FORMAT displays the date d as required by the expression f

SELECT DATE_FORMAT ('2011.11.11 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11) / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 11:11:11 AM

10. DAYNAME (d) returns the day of the week, such as Monday,Tuesday

SELECT DAYNAME ('2011-11-11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11);-return Friday

11. DAYOFMONTH (d) the date of calculation d is the day of the month

SELECT DAYOFMONTH ('2011-11-11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11)

12. DAYOFWEEK (d) date d what day is today, 1 Sunday, 2 Monday, and so on

SELECT DAYOFWEEK ('2011-11-11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11);-return 6

13. DAYOFYEAR (d) the date of calculation d is the day of this year

SELECT DAYOFYEAR ('2011-11-11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11)

14. EXTRACT (type FROM d) gets the specified value from date d, and type specifies the returned value

Available values for type are:

MICROSECOND

SECOND

MINUTE

HOUR

DAY

WEEK

MONTH

QUARTER

YEAR

SECOND_MICROSECOND

MINUTE_MICROSECOND

MINUTE_SECOND

HOUR_MICROSECOND

HOUR_SECOND

HOUR_MINUTE

DAY_MICROSECOND

DAY_SECOND

DAY_MINUTE

DAY_HOUR

YEAR_MONTH

SELECT EXTRACT (MINUTE FROM '2011-12-13 14-14-15-15-16');-return 15

15. DAYOFWEEK (d) date d what day is today, 1 Sunday, 2 Monday, and so on

SELECT DAYOFWEEK ('2011-11-11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11 / 11);-return 6

16. UNIX_TIMESTAMP () gets the timestamp

SELECT UNIX_TIMESTAMP ('2019-2-19'); SELECT UNIX_TIMESTAMP (expression);-return 1550505600

17. FROM_UNIXTIME () timestamp turns the date

SELECT FROM_UNIXTIME (1550505600);-return 2019-02-19 00:00:00SELECT FROM_UNIXTIME (1550505600,'% YMY% mMel% d');-return all the contents of the article "examples of the use of MySQL date functions" above 2019-02-19, thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report