The implementation method of subtracting 3 days from the current time of MySQL (detailed explanation of MySQL time function)

foreword

MySQL provides many built-in time functions, which can be used to obtain the current time, calculate time difference, convert time format, etc.


1. The current time minus 3 days

SELECT DATE_SUB(NOW(), INTERVAL 3 DAY);

2023-07-05 15:58:03

2. Get the date one month ago

SELECT DATE_SUB(NOW(), INTERVAL 1 MONTH);

2023-06-08 16:03:17

3. Get the date three days ago and one month ago

SELECT DATE_SUB((DATE_SUB(NOW(), INTERVAL 3 DAY)), INTERVAL 1 MONTH) AS M_DATE
, DATE_FORMAT(DATE_SUB(CURDATE(), INTERVAL 1 MONTH), '%Y%m') AS M_DATE_EQ;

2023-06-05 16:04:49 | 202306

4. Calculate the difference in days between two dates

SELECT DATEDIFF('2023-01-01', '2022-12-01');

31


Summarize

If this article is helpful to you, I hope that the big guys can 关注, 点赞, 收藏, 评论support a wave, thank you very much!
Please correct me if I am wrong!!!

Reference 1

Guess you like

Origin blog.csdn.net/weixin_42326851/article/details/131613028