Get the App
SLTechnology News&Howtos  ›  Database  › 

Mysql database fetches statements before and after seconds, minutes, hours and days.

Shulou Source: shulou.com Published: 2022-06-01 03:30:08 10月04日 Update

Take the current time:

Select current_timestamp

Output: 2016-06-16 16:12:52

Select now ()

Output: 2016-06-16 16:12:52

Take one minute before the current time:

Select SUBDATE (now (), interval 60 second)

Output: 2016-06-16 16:11:52

Take the next minute of the current time:

Select ADDDATE (now (), interval 60 second)

Output: 2016-06-16 16:13:52

By changing the units above. You can take the time of minutes, hours and days.

Take the time of the previous minute:

Select SUBDATE (now (), interval 1 minute)

Output: 2016-06-16 16:16:38

Take the time of the previous hour:

Select SUBDATE (now (), interval 1 hour)

Output: 2016-06-16 15:17:38

Take the time of the previous day:

Select SUBDATE (now (), interval 1 day)

Output: 2016-06-15 16:17:38

# #

One minute after taking:

Select ADDDATE (now (), interval 1 minute)

Output: 2016-06-16 16:17:38

One hour after taking:

Select ADDDATE (now (), interval 1 hour)

Output: 2016-06-16 17:17:38

Take the time of the day after:

Select ADDDATE (now (), interval 1 day)

Output: 2016-06-17 16:17:38

The following is a supplement:

Mysql gets yesterday's date, today's date, tomorrow's date, and the time of the previous hour and the next hour

1. Current date

Select DATE_SUB (curdate (), INTERVAL 0 DAY)

2. Tomorrow's date

Select DATE_SUB (curdate (), INTERVAL-1 DAY)

3. Yesterday's date

Select DATE_SUB (curdate (), INTERVAL 1 DAY)

4. The previous hour

Select date_sub (now (), interval 1 hour)

5. The next hour

Select date_sub (now (), interval-1 hour)

6. The first 30 minutes

Select date_add (now (), interval-30 minute)

7. The last 30 minutes

Select date_add (now (), interval 30 minute)

If you still don't have what you want, you can check out the relevant articles below. Thank you for your support.

Tags: Time output hour date unit article or face change support data database statement Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno macOS Apple Shulou Tech Info