Difference between two Dates

Here’s some useful code if you need to know how much time has elapsed between two days.

        DateTime oldDate = new DateTime(2005, 7, 31);

        DateTime newDate = DateTime.Now;


        // Difference in days, hours, and minutes.

        TimeSpan timeSpan = newDate - oldDate;


        // determine how many days are in the time span

        int differenceInDays = timeSpan.Days;


        labelDateDifference.Text = differenceInDays.ToString();

Comments (0)

Skip to main content