|
-
Feb 20th, 2010, 04:30 PM
#1
Thread Starter
Addicted Member
Dates...
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!
-
Feb 20th, 2010, 05:28 PM
#2
Hyperactive Member
Re: Dates...
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
-
Feb 20th, 2010, 05:39 PM
#3
Thread Starter
Addicted Member
Re: Dates...
And for format DD/M/YEAR?
-
Feb 20th, 2010, 10:26 PM
#4
Re: Dates...
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
- Coding Examples:
- Features:
- Online Games:
- Compiled Games:
-
Feb 21st, 2010, 03:23 AM
#5
Re: Dates...
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)
-
Feb 21st, 2010, 09:08 AM
#6
Thread Starter
Addicted Member
Re: Dates...
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
This is the best way to do this. Thank you.
-
Feb 21st, 2010, 09:12 AM
#7
Re: Dates...
 Originally Posted by hepeci
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
This is the best way to do this. Thank you.
Your best way won't compile.
-
Feb 21st, 2010, 11:47 AM
#8
Lively Member
Re: Dates...
 Originally Posted by dbasnett
Your best way won't compile.
It does, are you sure youve got the list box on your form?
Whats the error?
-
Feb 21st, 2010, 12:46 PM
#9
Re: Dates...
Add this as the very first line of your program:
Option Strict On
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
|