Link to home
Start Free TrialLog in
Avatar of RIAS
RIASFlag for United Kingdom of Great Britain and Northern Ireland

asked on

Find how many days remaining

Hello,

How can I find a count for many days remaining for a Sunday  in that week .
Example:
Date : 24/09/2019 which is Tuesday
The date on Sunday in that week  will be 29/09/2019
So the count is 5

I will be provided with the current date, need to find the remaining days count till Sunday.

Regards
Avatar of Peter Chan
Peter Chan
Flag of Hong Kong image

Try
select case substring(datename(dw,getdate()),1,3) when 'Sat' then 1 when 'Fri' then 2 when 'Thu' then 3 when 'Wed' then 4 when 'Tue' then 5 when 'Mon' then 6 when 'Sun' then 0 end
go

Open in new window

Avatar of AndyAinscow
Logic:

daysremaining = 0
while not dategiven.DayOfWeek = sunday
  daysremaiing = daysremaining+1
  dategiven = dategiven+1 (day)
end while
ASKER CERTIFIED SOLUTION
Avatar of Misha
Misha
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Hi Experts,

Thanks for the help.
Misha, thanks will try the code and brb
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RIAS

ASKER

Thank you all.
Gustav Brock your code is spot on!!!! Thanks!!
You are welcome!