T-SQL solution to find out how many weeks have passed between 2 dates.

I need a T-SQL solution to find out how many weeks have passed between 2 dates.
The week starts on a Monday and ends on a Friday.
So if the date was this Thursday and the new date is next Monday I need the answer to be 1.
In other words I do not need to be counting full weeks. This is necessary to change dates in multiple weeks of a project when a target date changes.
So if the target date is Thursday 2018/12/06 and it's changed to Tuesday 2018/12/18 my answer would be 2. (remember I do not count full weeks). Each instance passed a Monday is considered a week.  And I need it to start changing (adding the weeks) with the current weeks Monday. So if today was Tuesday 11/27/2018 these would be my old dates and new dates. (There are dates before the target date and after the target date).  

Original dates.                 New dates
M-11/26/18:F-11/30/18  M-12/10/18:F-12/14/18  
M-12/03/18:F-12/07/18  M-12/17/18:F-12/21/18   Target date
M-12/10/18:F-12/14/18  M-12/24/18:F-12/28/18
M-12/17/18:F-12/21/18  M-12/31/18:F-01/04/19
Chuck LoweAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ste5anSenior DeveloperCommented:
Well, it's imho simple, depending on the used SQL dialect, e.g. T-SQL:

SELECT DATEDIFF(DAY, DateFrom, DateTo) / 7 AS Weeks FROM yourTable;

Open in new window

0
Vikas GargAssociate Principal EngineerCommented:
Hello,

You can try this query

declare @from datetime= '9/1/2018'
declare @to datetime  = '9/17/2018' 

select datediff(day, -7, @to)/7-datediff(day, -6, @from)/7 MondayCount

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pcelbaCommented:
How many weeks passed two dates:
DECLARE @OriginalDate Date = '2018/12/06'
DECLARE @NewDate Date =  '2018/12/07'

SELECT DATEDIFF(week, @OriginalDate, @NewDate)

Open in new window

So you can add  7 * DATEDIFF(week, @OriginalDate, @NewDate)  to all your existing date values and you should be fine.
0
Become a Certified Penetration Testing Engineer

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

Chuck LoweAuthor Commented:
Exactly what I needed.

Thanks!
0
pcelbaCommented:
Just to clarify - what should be the result for date change from Monday this week to Friday next week?  1 week or 2 weeks?.
0
Chuck LoweAuthor Commented:
1 Week
0
pcelbaCommented:
Good. The accepted solution calculates this difference as 2 weeks:
declare @from datetime= '8/27/2018'
declare @to datetime  = '9/7/2018' 
select datediff(day, -7, @to)/7-datediff(day, -6, @from)/7 MondayCount

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.