Getting the wrong number of days for days between dates

Discussion in 'Visual Basic ( VB )' started by Kenneth Reid, Dec 31, 2021.

  1. Kenneth Reid

    Kenneth Reid New Member

    Joined:
    Dec 22, 2021
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Gender:
    Male
    Occupation:
    Disabled
    I am trying to write a function to get the "Days between dates". The code I have (for a console application) is shown below. For some reason, it is not giving the correct number of days between dates. How do I get this to work correctly?
    Code:
    Dim BeginningDate As Date
    Dim EndingDate As Date
    
    Dim DaysBetweenDates = DateDiff(DateInterval.Day, EndingDate.Date, BeginningDate.Date)
    Dim msg = String.Format(" days between dates.", DaysBetweenDates)
    
    Console.WriteLine("                          Days Between Dates Subroutine")
    For A = 1 To 5
         Console.WriteLine(" ")
    Next
    
    Console.WriteLine("Enter the beginning date (xx/xx/xxxx): ")
    BeginningDate = Console.ReadLine()
    Console.WriteLine("Enter the ending date (xx/xx/xxxx): ")
    BeginningDate = Console.ReadLine()
    
    Console.WriteLine(DateDiff("d", EndingDate, BeginningDate) & msg)
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice