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 大小即可。

代碼並未實現以上需求 僅記錄思路。

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM