1. [RESOLVED] get days range add

Hello.
I can't get this in my mind.
I want to get the total days in range, today to an x month.
I know I have to do this:
(EndDate.Date - StartDate.Date).Days

The issue is that I am not sure how would I calculate the enddate by the exact date.
So if I need to add 2 months I would need to calculate the endate , for example 30+31 = 61 not 60.
I have a difficult day and I really cannot get this in my mind so any help would be appreciated.

2. Re: get days range add

The Date Class has .AddDays(), and .AddMonths(), so there’s no need to calculate the number of days in 2 months

3. Re: get days range add

I think it depends how you consider your month. In term of time or effort.
If it is in term of date then it is easy : 12/03 + 2 months = 12/05
in term of effort, you need to define the number of days in your month (eg : 30 days ) : 12/03 +2 months (2*30 days) =10/05, 12/07 +2 months = 09/09.
Personally, I would do that in term of time.

4. Re: get days range add

I needed this a while back, see if it helps

Code:
```Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim dc As New System.Globalization.GregorianCalendar()
Dim formatInfo = System.Globalization.DateTimeFormatInfo.CurrentInfo
ListBox1.Items.Add("Jahr" & "-" & "Tage " & "-" & "Monat ")
'schreibe in Text datei
Using sw As New IO.StreamWriter("E:\TestFolder\TestfileYear_Days.txt")
For i = 2020 To 2023
ListBox1.Items.Add(CStr(i) & " - " & dc.GetDaysInYear(i))
For y = 1 To 12
Dim nDays As New DateTime(i, y, 1)
Dim monthName = formatInfo.GetMonthName(y)
sw.WriteLine(CStr(i) & " " & dc.GetDaysInMonth(i, y) & " " & monthName)
Do While nDays.Month = y
sw.WriteLine(nDays.ToString("dd.MM.yyyy"))

Loop
'zeige in Listbox
ListBox1.Items.Add(CStr(i) & " - " & dc.GetDaysInMonth(i, y) & " - " & monthName)
Next

Next
sw.Close()
End Using

End Sub```

5. Re: get days range add

Thanks to all.

Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•