需求比较两个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 大小即可。

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

  

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2021-11-09
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-07-07
  • 2021-12-06
  • 2021-11-21
  • 2021-09-20
  • 2022-12-23
相关资源
相似解决方案