Get missing dates RRS feed

  • Question

  • User-49671077 posted

    How can get missing date from set of dates Exp:

    Month: December 01/12/2018 - 31-12-2018







    and so on

    I want to get 02/12/2018 and 05/12/2018 so on missing dates


    Friday, December 21, 2018 7:23 AM

All replies

  • User-943250815 posted

    For Datetime type this sample returns missing dates in Range

    Public Shared Iterator Function GetDateRange(ByVal startDate As DateTime, ByVal endDate As DateTime) As IEnumerable(Of DateTime)
        If endDate < startDate Then Throw New ArgumentException("endDate must be greater than or equal to startDate")
        While startDate <= endDate
          Yield startDate
          startDate = startDate.AddDays(1)
        End While
      End Function
    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim DtRange = GetDateRange(New Date(2018, 5, 1), New Date(2018, 5, 7))
        Dim LstDates As New List(Of DateTime)
        LstDates.Add(New Date(2018, 5, 1))
        LstDates.Add(New Date(2018, 5, 1))
        LstDates.Add(New Date(2018, 5, 3))
        LstDates.Add(New Date(2018, 5, 4))
        LstDates.Add(New Date(2018, 5, 6))
        LstDates.Add(New Date(2018, 5, 7))
        Dim MissingDates = From p In DtRange.ToList Where Not LstDates.Contains(p) Select p
        Exit Sub

    Friday, December 21, 2018 12:09 PM
  • User61956409 posted

    Hi kafsar,


    How can get missing date from set of dates 

    To achieve the requirement, please refer to the following code snippet.

    Dim list_of_missing_date As List(Of String) = New List(Of String)
    Dim start_date As Date = New Date(2018, 12, 1)
    For index = 0 To Date.DaysInMonth(2018, 12) - 1
        If Not checkdatefunc(start_date.AddDays(index)) Then
        End If
    Private Function checkdatefunc(ByVal currentdate As Date) As Boolean

    'list_of_date is a list used to store your dates 01/12/2018, 03/12/2018, 04/12/2018 etc
    If list_of_date.Contains(currentdate) Then Return True End If Return False End Function

    Test Result:

    With Regards,

    Fei Han

    Tuesday, December 25, 2018 2:19 AM