C# 两个日期相减核算月份

 #region 两个日期相减得月份
    public string GetMonth(string startTime, string endTime)
    {
        string msg = string.Empty;
        DateTime startDate = DateTime.Parse(startTime);
        DateTime endDate = DateTime.Parse(endTime);   //结束时间-起始时间
        int totalMonth = endDate.Year * 12 + endDate.Month - startDate.Year * 12 - startDate.Month;
        if (totalMonth < 3)
        {
            msg = "3个月以下";
        }
        else if (totalMonth >= 3 & totalMonth < 12)
        {
            msg = "3月-1年";
        }
        else if (totalMonth >= 12 & totalMonth < 24)
        {
            msg = "1年-2年";
        }
        else if (totalMonth >= 24 & totalMonth < 36)
        {
            msg = "2年-3年";
        }
        else if (totalMonth >= 36 & totalMonth < 48)
        {
            msg = "3年-4年";
        }
        else if (totalMonth >= 48)
        {
            msg = "5年以上";
        }
        return msg;
    }
    #endregion 

 

 int totalMonth = endDate.Year * 12 + endDate.Month - startDate.Year * 12 - startDate.Month;

* 核算:开始日期-结束日期=月份数

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值