How to calculate number of days between 2 Dates/time

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • AXRabbit
    New Member
    • Feb 2009
    • 6

    How to calculate number of days between 2 Dates/time

    Hi guys, I am currently doing a Car rental website project. Like my Car collection and return date is like in the website. http://www.avis.com/car-rental/avisHome/home.ac

    Well i need a function or method to calculate the number of days between Collection date/time and return date/time.

    I tried DateDiff(DateIn terval.DayOfYea r, startdate, enddate)

    But i cant get the answer.

    and also..
    '
    I also tried set
    Dim d as integer
    DateDiff("d",Da te1,Date2)
    d= label.text

    '


    But failed.



    Please assist.


    Time spent in reading my problem is deeply appreciated. Hope that anyone who know can help.

    Thanks~
    -Kelvin
  • PRR
    Recognized Expert Contributor
    • Dec 2007
    • 750

    #2
    Try using TimeSpan
    Code:
    DateTime now1 = DateTime.Now;
                DateTime extra = DateTime.Now.AddDays(5);
    
                TimeSpan diff = extra - now1;
    
                Console.WriteLine("Days : "+diff.Days+"\nHrs"+diff.Hours+ "\nMin "+diff.Minutes);

    Comment

    Working...