Click here to Skip to main content
15,905,508 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Explanation:

The form design will be 2 datetimepickers, 1 datagridview and a button. users may select date rages by select from datetimepicker1 as start date and datetimepicker2 as end date, after finish the selection click on button it will populate the ranged dates in datagridview.

example: 01/01/2014
02/01/2014
03/01/2014
04/01/2014
05/01/2014
06/01/2014
07/01/2014
08/01/2014
09/01/2014

current tested codes workout:

result: only change in days! months and years still in fix!

VB
Public Sub pickme()
        Dim daysInMonth1 As Integer = DateTimePicker2.Value.Date.Day + -DateTimePicker1.Value.Date.Day
        Dim daysCollection() As String = New String(daysInMonth1) {}
        Dim index As Integer

        For index = 0 To daysInMonth1 - 1 Step index + 1
            daysCollection(index) = (index + 1).ToString() + "/4/2014"
            MsgBox(daysCollection(index)) ' test result 
        Next
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        pickme()
    End Sub


Question:

how can i populate {days} {months} {years} from the ranged dates been selected?
Posted
Comments
[no name] 7-Apr-14 22:06pm    
Your question does not really make a whole lot of sense. The Value property of a DateTimePicker is a DateTime which has Day, Month and Year properties. So what, exactly, is the problem?
donaldliaw87 7-Apr-14 22:22pm    
sorry, am asking the wrong way, to faster the asking... how to show ranged dates picked from datetimepickers and show results like this? (01/01/2014
02/01/2014
03/01/2014
04/01/2014
05/01/2014
06/01/2014
07/01/2014
08/01/2014
09/01/2014)

1 solution

See the following example for getting a list of dates between 2 dates:
VB
Public Module Module1
    Public Sub Main()

        Dim startDate As DateTime = new DateTime(2014,4,1)
        Dim endDate As DateTime  = new DateTime(2014,4,8)
        While startDate <= endDate
            Console.WriteLine(startDate)
            startDate = startDate.AddDays(1)
        End While

    End Sub
End Module

You can place these dates in a list, then
for populating datagridview, refer: datagridview-vbnet[^]
 
Share this answer
 
v2
Comments
donaldliaw87 8-Apr-14 4:46am    
hi Peter Leow thx for the guides!

i still got another issue: when i change the declaration of datetime to (dim startdate as DateTime = new DateTime (DateTimePicker1.value) its gave me an error stated "value of type date cannot convert to long"

i try to pass the both datetimepickers.value to variable string still face the same error!
Peter Leow 8-Apr-14 6:15am    
The return value from a datetimepicker is already a datetime, so just do this:
Dim startdate as DateTime = DateTimePicker1.Value;

Refer: http://www.tutorialspoint.com/vb.net/vb.net_date_time_picker.htm
donaldliaw87 8-Apr-14 21:36pm    
Tq Peter!!!!, your clear guidance reminded me "must understand and check the datatype" before coding!
Peter Leow 8-Apr-14 22:57pm    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900