How can I loop through each date in a given time period

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sasasasa
    New Member
    • Apr 2010
    • 29

    How can I loop through each date in a given time period

    How can I loop through each date in a given time period so that I can add those dates as a column name in a table.
    I want to create datatable with the person's name and hours he worked in a given time period. The user will select the dates and I want to show each day/date in that table as a column name. I have no idea how to do it. Please help.
  • Aimee Bailey
    Recognized Expert New Member
    • Apr 2010
    • 197

    #2
    Usually you'd just iterate using the Days value of a TimeSpan, easy peasy :)

    Code:
    Public Function LoopThroughDates(ByVal dFrom As DateTime, ByVal dTo As DateTime) _
                                            As List(Of DateTime)
            Dim r As New List(Of DateTime)
    
            Dim diff As TimeSpan = dTo - dFrom
    
            For d = 0 To diff.Days
                r.Add(dFrom.Date.AddDays(d))
            Next
    
            Return r
        End Function

    Comment

    Working...