Difference in months between two dates

前端 未结 30 1203
天命终不由人
天命终不由人 2020-11-22 11:02

How to calculate the difference in months between two dates in C#?

Is there is equivalent of VB\'s DateDiff() method in C#. I need to find difference in

30条回答
  •  无人及你
    2020-11-22 11:54

    This worked for what I needed it for. The day of month didn't matter in my case because it always happens to be the last day of the month.

    public static int MonthDiff(DateTime d1, DateTime d2){
        int retVal = 0;
    
        if (d1.Month

提交回复
热议问题