Query Mysql Time Range

Asked

Viewed 91 times

0

Hello, would need to make a query in a time interval in mysql, this interval would like it to be the START (current date) END ( current date + 365 days (1 year)), tried with KURDATE() but it did not work.

 BETWEEN  CURDATE()  AND CURDATE() + 365

2 answers

0


You can use "DATE_ADD()" together with "KURDATE()". This function takes 3 parameters, which are: The date that will be modified, the range that can be positive or negative and finally the type of interval.

Types of ranges that can be used:

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 * FROM `nome_da_tabela` WHERE `nome_da_coluna` BETWEEN CURDATE() AND DATE_ADD(CURDATE(), INTERVAL 1 YEAR)

0

You can use:

SELECT * FROM docs WHERE data BETWEEN date(now())-20 AND data

The select above returns amid the current date less 20 days and the current date.

http://sqlfiddle.com/#! 9/6a03df/4/0

Browser other questions tagged

You are not signed in. Login or sign up in order to post.