C # Calculates the number of days difference between two dates

Source: Internet
Author: User

Note: For example, between 1900-01-01 and 1900-01-01, one day

private static int DateDiff (DateTime datestart, datetime dateend)        {            datetime start = Convert.todatetime ( Datestart.toshortdatestring ());            DateTime end = Convert.todatetime (datestart.toshortdatestring ());            TimeSpan SP = end. Subtract (start);            Return sp. Days;        }

Related Properties for TimeSpan:

Related properties and functions add: Adds to another timespan value. Days: Returns the TimeSpan value that is calculated in day. Duration: Gets the absolute value of the timespan. Hours: Returns the TimeSpan value computed in hours milliseconds: Returns the TimeSpan value computed in milliseconds. Minutes: Returns the TimeSpan value computed in minutes. Negate: Returns the inverse number of the current instance. Seconds: Returns the TimeSpan value computed in seconds. Subtract: Subtracts another TimeSpan value from it. Ticks: Returns the number of ticks for the timespan value. Totaldays: Returns the number of days that the TimeSpan value represents. TotalHours: Returns the number of hours that the timespan value represents. TotalMilliseconds: Returns the number of milliseconds represented by a timespan value. Totalminutes: Returns the number of minutes represented by a timespan value. TotalSeconds: Returns the number of seconds represented by a timespan value.

C # Calculates the number of days difference between two dates

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.