-
Nov 24th, 2021, 08:59 AM
#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.
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
-
Nov 24th, 2021, 09:26 AM
#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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Nov 24th, 2021, 09:35 AM
#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.
Last edited by Delaney; Nov 24th, 2021 at 04:07 PM.
Reason: typo
The best friend of any programmer is a search engine
"Don't wish it was easier, wish you were better. Don't wish for less problems, wish for more skills. Don't wish for less challenges, wish for more wisdom" (J. Rohn)
“They did not know it was impossible so they did it” (Mark Twain)
-
Nov 24th, 2021, 09:43 AM
#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 ")
ListBox1.Items.Add("-----------------------------------------")
'schreibe in Text datei
Using sw As New IO.StreamWriter("E:\TestFolder\TestfileYear_Days.txt")
For i = 2020 To 2023
ListBox1.Items.Add("-----------------------------------------")
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"))
'ListBox1.Items.Add(nDays.ToString("dd.MM.yyyy"))
nDays = nDays.AddDays(1)
Loop
'zeige in Listbox
ListBox1.Items.Add(CStr(i) & " - " & dc.GetDaysInMonth(i, y) & " - " & monthName)
Next
Next
sw.Close()
End Using
End Sub
to hunt a species to extinction is not logical !
since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.
-
Nov 24th, 2021, 10:45 AM
#5
ἄνδρα μοι ἔννεπε, μοῦσα, πολύτροπον, ὃς μάλα πολλὰ
πλάγχθη, ἐπεὶ Τροίης ἱερὸν πτολίεθρον ἔπερσεν·
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|