Hello!
I have two dates.
For example:
12.1.2009
And
15.7.2010
How to print all dates between these two dates in one listbox, for example:
12.1.2009
13.1.2009
14.1.2009
........
14.7.2010
15.7.2010
Thanks!
Printable View
Hello!
I have two dates.
For example:
12.1.2009
And
15.7.2010
How to print all dates between these two dates in one listbox, for example:
12.1.2009
13.1.2009
14.1.2009
........
14.7.2010
15.7.2010
Thanks!
Try something like this. Create a listbox on a form called lstDates. Then populate it with the code below on a click event of a button, for example. I am sure there are different ways to do this but here is a way I thought off of the top of my head.....
Oh yeah I have the dates in USA format as M/DD/YYYY.
Code:Dim startDate As DateTime = #1/12/2009#
Dim endDate As DateTime = #7/15/2010#
While startDate <= endDate
Me.lstDates.Items.Add(startDate)
startDate = startDate.AddDays(1)
End While
And for format DD/M/YEAR?
the date format used will be according to your PC's regional settings, so you just need to change startDate + endDate to DD/M/YYYY format
Code:'DD/M/YEAR
'Dates are not stored as strings
'but a string can be parsed into a date
'12.1.2009
'And
'15.7.2010
Dim ci As System.Globalization.CultureInfo = System.Globalization.CultureInfo.InvariantCulture
Dim stdt, enddt As DateTime
stdt = DateTime.ParseExact("12/1/2009", "dd/m/yyyy", ci)
enddt = DateTime.ParseExact("15/7/2010", "dd/m/yyyy", ci)
This is the best way to do this. Thank you.Code:Dim startDate As DateTime = "1/12/2009"
Dim endDate As DateTime = "15/7/2010"
While startDate <= endDate
Me.lstDates.Items.Add(startDate)
startDate = startDate.AddDays(1)
End While
End Sub
Add this as the very first line of your program:
Option Strict On