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

How to realize time processing operation in mysql

2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

This article will explain in detail how to achieve time processing operation in mysql. The content of the article is of high quality, so the editor will share it for you as a reference. I hope you will have some understanding of the relevant knowledge after reading this article.

1. Store date and time with now ()

two。 Use curdate () / current_date to store dates

3. Storage time with time ()

4. Use year () to get the year

5. Get month with month ()

6. Get the date in the month with day () or dayofmonth ()

7. Get yesterday using date_sub (curdate (), interval 1 day) / date_sub (current_date,interval 1 day)

Or curdate ()-interval 1 day; [- Table minus 1 day, if + means plus 1 day]

Or to_days (curdate ())-to_days (field name) = 1

[note:]

a. There is a to_days function, but no to_months () and to_years () functions.

The b.to_days () function converts the date to the number of days from the year AD.

8. Use date_sub (curdate (), interval 1 month) / date_sub (current_date (), interval 1 month) one month before getting

9. Get last year using date_sub (curdate (), interval 1 year) / date_sub (currentdate (), interval 1 year)

10. Get hourly hour ()

11. Get demultiplexed minute ()

twelve。 Get the second second ()

13. Creation time mktime (0JOPE0, "$_ POST []", "$_ POST []", "$_ POST []")

14. To get the sql statement from two days ago (including yesterday) is:

Select * from tablename where [field name] between date_sub (curdate (), interval 2 day) and curdate ()

Or:

Select * from tablename where to_days (curdate ())-to_days (field name) select DAYOFYEAR ('1998-02-03')

-> 34

18.DAYNAME (date)

Returns the name of the week of date.

Mysql > select DAYNAME ("1998-02-05")

-> 'Thursday'

19.QUARTER (date)

Returns the quarter of the year in date, ranging from 1 to 4. (1-3 for 1-3 months for 1-6 months for 2-7-9 months for 3-4 months)

On how to achieve time processing operations in mysql to share here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

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

Database

Wechat

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

12
Report