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

This question has already been answered. Start a new discussion instead.