Format A TimeSpan With Years

后端 未结 6 1218
深忆病人
深忆病人 2020-11-27 06:45

I have a class with 2 date properties: FirstDay and LastDay. LastDay is nullable. I would like to generate a string in the format of

6条回答
  •  一向
    一向 (楼主)
    2020-11-27 07:32

    I think this should work:

    public static int DiffYears(DateTime dateValue1, DateTime dateValue2)
    {
        var intToCompare1 = Convert.ToInt32(dateValue1.ToString("yyyyMMdd"));
        var intToCompare2 = Convert.ToInt32(dateValue2.ToString("yyyyMMdd"));
        return (intToCompare2 - intToCompare1) / 10000;
    }
    

提交回复
热议问题