Show data from today plus 1 week ahead in mysql

0

Good morning / afternoon / evening. I have a table in mysql that has a datetime field current_timestamp, name: Upload Date. What I need is to show the records where the load date is contemplated between the current day and 7 days ahead since the records are loaded in an agenda and what I need to show is the expiration of that data that is charged "In these 7 days expire the following records ... "and show them, always taking as the start date the current date and end date, current date + 7 days.

    
asked by Juan 23.08.2017 в 21:26
source

1 answer

3

To calculate a week after the current one you can use:

NOW() + INTERVAL 7 DAY

As NOW () returns the date and time, to pick up the date only you can use:

CURDATE() + INTERVAL 7 DAY

Used in a query would be such that:

SELECT * FROM Orders WHERE OrderDate BETWEEN CURDATE() and CURDATE() + INTERVAL 7 DAY;

It will show you the records in an interval from the current day to seven days later.

  

EDITION (explanation)

The NOW () function retrieves the date and time format: yyyy-MM-dd hh: mm: ss , so% co_of% the OrderDate that would look for it would be from yyyy-MM-dd (today) hh: mm: ss to yyyy-MM-dd (today + 7) hh: mm: ss so yes they recorded a data with an hour for example 08:25:05 and when making a query you do it at 08:25:06 that record would not be found, therefore and as said @PatricioMoracho in the comment. The most correct option for this problem of showing only seven more days is to use CURDATE ()

    
answered by 23.08.2017 / 21:44
source