Misunderstanding mysql statement DATE_ADD (NOW () INTERVAL)

I am working on a page containing the following mysql line. The main goal is simply to combine the current digit of the week with the current date.

$sql = "select distinct weekNum from " . DB_PREFIX . "schedule where DATE_ADD(NOW(), INTERVAL " . SERVER_TIMEZONE_OFFSET . " HOUR)"

According to my research, DATE_ADD() it allows you to add a certain number of days to a date.

So I guess that DATE_ADD(NOW()adds the current date to ... well date?

What exactly is doing INTERVALin this status.

Any supporting explanatory spaces clarifying the above statute would be greatly appreciated.

+4
source share
4 answers

As far as I can see, this statement is trying to control the difference in the time zone.

 INTERVAL " . SERVER_TIMEZONE_OFFSET . " HOUR

( ) ( ), .

from https://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_date-add

DATE_ADD (, INTERVAL), DATE_SUB (, INTERVAL) . date . expr - , , . expr - ; a - . unit - , , .

+2
DATE_ADD(NOW(), INTERVAL 2 HOURS)

- 2

- DATE_ADD(date, INTERVAL value unit)

→ -

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

, , , , .

DATE_SUB (, INTERVAL), , . [https://www.w3schools.com/sql/func_mysql_date_add.asp]

+2

- "" . .

, GMT-0.

+2

The function DATE_ADD()has two parameters:
1. the date on which you want to add any interval 2. the number of units with the keywords INTERVAL numbe UNITS, where "UNITS" can be any supported time value between MILLISECONDS ~ YEAR

DATE_ADD () is a synonym for ADDDATE ().

+2
source

Source: https://habr.com/ru/post/1691494/


All Articles