A
A
anonymous2017-06-21 23:08:37
SQL Server
anonymous, 2017-06-21 23:08:37

How to write a query with a date?

How to write a request with a date correctly (I can’t write it correctly because I can’t understand)
"Display the number of new products in the store - products that were delivered during the last week (7 days)" I
did this:

SELECT COUNT(Product.idProduct) FROM Product WHERE Product.idProduct IN
 (SELECT Dalivery.idProduct FROM Dalivery 
WHERE (YEAR(Dalivery.DateDelivery) BETWEEN YEAR(DATE_ADD(GETDATE(), INTERVAL -7 DAY)) AND GETDATE() ) );

And I'm doing something wrong. I did n't find an
explanation for working with dates .

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
d-stream, 2017-06-22
@anonymouss

stupidly difference in days between date and "today":
the difference is less than or equal to 7 - for the last 7 days
, but if a "hit" in a calendar week is required, the expression will be somewhat more poignant

A
Andrey Skorzhinsky, 2017-06-23
@AndyKorg

A small FAQ on working with dates.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question