C
C
Charles Chaplin2015-03-30 20:39:52
PHP
Charles Chaplin, 2015-03-30 20:39:52

SQL query: how to select records in the range from today to the end of the week?

There is a table with attribute "date". I need to get from this table only those records that are in the range from today to the end of the week.
Found a similar query

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Rsa97, 2015-03-30
@Rsa97

....
 WHERE `date` BETWEEN CURDATE() 
              AND DATE_ADD(CURDATE(), INTERVAL 7-WEEKDAY(CURDATE()) DAY)

L
lnked, 2015-03-30
@lnked

SELECT * FROM `table` WHERE STR_TO_DATE(`date`, '%d.%m.%Y') >= CURDATE() AND STR_TO_DATE(`date`, '%d.%m.%Y') <= CURDATE() + INTERVAL 7 DAY

D
dev2expert, 2015-03-31
@dev2expert

If you need any other day of the week, then replace 8 with another number.

SELECT * 
FROM `table`
WHERE (`data` >= DATE(NOW()) AND 
       `data` <= DATE (DATE('Y-m-d') + INTERVAL (8 - DAYOFWEEK(DATE('Y-m-d'))) DAY));

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question