SQLTeam.com | Weblogs | Forums

If the expiration date of promo is today the promo still available, and by the other day that's the time that the promo will not be available


#1

Can you help me with my sql query problem, For example the day today is 2016/12/12 and the expiration date is today(2016/12/12). I want that if the expiration date of promo is today, the promo are still available, then at the next day the promo will not be available or expired already.
here's my query but something wrong because if the expiration date is today the promo is already not available, what i want is if the expiration date of promo is today the promo still available, and by the other day that's the time that the promo will not be available. im sorry my english is not that good! Thanks in advance :slight_smile:
ALTER procedure [dbo].[promodate]

as
begin
UPDATE
tblpromo
SET
Status = 0
WHERE
Status = 1
AND
EndDate < GETDATE()
end


#2

That is an end date earlier than "now", which includes the date/time of "now".

Midnight last night (i.e. 12-Dec-2016) / tonight (i.e. 13-Dec-2016) would be

SELECT DATEADD(Day, DATEDIFF(Day, 0, GetDate()), 0) AS [LastNight],
       DATEADD(Day, DATEDIFF(Day, 0, GetDate())+1, 0) AS [Tonight]

#3

Thank you! so i will replace the EndDate < GETDATE() to
SELECT DATEADD(Day, DATEDIFF(Day, 0, GetDate()), 0) AS [LastNight],
DATEADD(Day, DATEDIFF(Day, 0, GetDate())+1, 0) AS [Tonight]???


#4

You need to replace GETDATE() with one of the two examples I have provided.

You can exec my whole example to see what values you get. I think you want the second one, but I'd prefer that you check that!


#5

Thank you so much I will try it! :slight_smile: