C# 比较日期格式中的年月大小

需求比较两个DateTime类型的年月

类似:只能是当月或当月之前的数据(只能是1号)

思路:将两个需要对比的日期 全部转换成月份 再做比较   

   如:DateTime dt_Now=new DateTime.Now();

  string dt_other="2020-03-02";

  DateTime othertime = DateTime.Parse(dt_other);//转换日期

  int now_Month = dtNow.Year * 12 + dtNow.Month;

  int other_Month = dt_other.Year * 12 + dt_other.Month;

比较 now_Month 和 other_Month 大小即可。

代码并未实现以上需求 仅记录思路。

  

原文地址:https://www.cnblogs.com/qixiaolan/p/14524312.html