Hi

I am trying to populate a listview with all the hours of the day in 30 minute intervals.

I can doing very basically from 0 to 24 with the following code:

Private Sub CreateTimeStep()

        For i = 0 To 25 Step 0.5

            lstDays.Items.Add(i)

        Next
    End Sub

but what i would like to do is have it display in 24 hour format e.g. 00:00, 00:30 ...etc

I have tried using the date.time variable but it just doesnt work.

Try this:

Dim d As Date = "00:00:00"
        For x As Integer = 0 To 47
            ListBox1.Items.Add(d.TimeOfDay.ToString)
            d = d.AddMinutes(30)
        Next

this looks like just the thing - many thanks - will update when tested

hi

your code worked fine but i just needed to get rid of the last zeros so used the following

Dim d As DateTime = FormatDateTime("00:00")
For x As Integer = 0 To 47
lstDays.Items.Add(FormatDateTime(d.TimeOfDay.ToString, DateFormat.ShortTime))
d = d.AddMinutes(30)
Next
End Sub

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.