troubleshooting Question

Number of weeks (plus left over days) between two dates

Avatar of clintnash
clintnashFlag for United States of America asked on
Visual Basic.NET
5 Comments1 Solution989 ViewsLast Modified:
I think that I have missed something quite elementary in my approach.  I have two dates, I need to calculate the number of weeks between the dates, plus any left over days.  For example StartDate - Thursday Oct 25  / EndDate Saturday November 3rd.  There are 10 days between these dates.  What I need is a formula that will return 1 week 3 days.  I have tried quite a few variations on the theme below.

Dim SeasonStart As Date = dtpStart.Text, Dim SeasonEnd As Date = dtpend.Text
Dim iDay As DayOfWeek
Dim dWeek As Decimal
Dim m_percentage, m_wholeNum, full_string, m_array() As String

iDay = DateDiff(DateInterval.WeekOfYear, SeasonStart, SeasonEnd)
dWeek = Math.Round((iDay / 7), 1, MidpointRounding.AwayFromZero)

full_string = dWeek.ToString("#.#")
m_array = Split(full_string, ".")
m_percentage = m_array(0)
m_wholenum = m_array(1)

label1.text = m_wholeNum & " weeks and " & m_pecentage & " days"

I have a rounding problem in every way I have approached it.  The next step in the process requires that I subtract a number of daysfrom the total number of days before I calculate weeks and months, so hopefully someone can suggest a method where I still have a number of days and then convert that to a number of weeks.

Any advice is, as always, greatly appreciated.
ASKER CERTIFIED SOLUTION
skyper3

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 1 Answer and 5 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 5 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros