C # how to calculate the number of days difference between the two dates

C # operations with the date when the calculation is the date most often calculate the difference between the number of days, then how does it work? The following small series to share with you.

Tools / materials

  • Visual Studio

Method / Step

  1. First, open VS, click on the following new project file, as shown below

    C # how to calculate the number of days difference between the two dates

  2. Then build a console program, the following structure shown in FIG.

    C # how to calculate the number of days difference between the two dates

  3. Then declare the calculated date to two, as shown in FIG.

    C # how to calculate the number of days difference between the two dates

  4. Next, the offset is calculated by the two dates Subtract function, as shown below

    C # how to calculate the number of days difference between the two dates

  5. Then a direct call to the offset attribute days, as shown in FIG.

    C # how to calculate the number of days difference between the two dates

  6. Finally, running the program can calculate the difference between the number of days of the date, as shown in FIG.

    C # how to calculate the number of days difference between the two dates

  7. Finally, in the calculation of the difference we must draw attention to certain plus 1

Released three original articles · won praise 2 · Views 2824

Guess you like

Origin blog.csdn.net/fangyuan621/article/details/105316967