Determining the difference between dates

后端 未结 8 1874
無奈伤痛
無奈伤痛 2020-12-10 04:34

I\'m trying to figure out a way for my program to take a date (like February 2nd, 2003) and show the difference between the two with another date (like April 2nd, 2012), exc

8条回答
  •  一生所求
    2020-12-10 05:32

    Since you are looking for mathematical formula , it will help you to find a solution to your problem. Let Y be the year,M be the month and D be the day. Do this calculation for both the dates.

    Total = Y* 365 + M*30 + D ,then find the difference between 2 totals of the corresponding dates.

    While multiplying 30 with M value ,you have to give the number of days in that month. You can do it with #define value or if loop. Similarly you can do for leap year too by multiplying 366 with Y .

    Hope this will help u....

提交回复
热议问题