LINQ中判断日期时间段
生活随笔
收集整理的這篇文章主要介紹了
LINQ中判断日期时间段
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1)轉換日期格式為DateTime類型
DateTime dtToday = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd"));//今天 DateTime dtNexDay = Convert.ToDateTime(DateTime.Now.AddDays(1).ToString("yyyy-MM-dd"));//明天 DateTime dtMonthFirstday = Convert.ToDateTime(new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1).ToString("yyyy-MM-dd"));//本月 DateTime dtThreeMonth = Convert.ToDateTime(new DateTime(DateTime.Now.Year, DateTime.Now.AddMonths(-3).Month, 1).ToString("yyyy-MM-dd"));//3個月前 DateTime dtYearFirstday = Convert.ToDateTime(new DateTime(DateTime.Now.Year, 1, 1).ToString("yyyy-MM-dd"));//今年2)使用LINQ判斷日期
var query = db.Query<UserInfo>().Where(c=>c.Date>dtToday&&c.Date<dtNexDay)
PS:一般判斷方法,使用DateTime的Compare方法
?
?
?
轉載于:https://www.cnblogs.com/HansZimmer/p/9239929.html
超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生總結
以上是生活随笔為你收集整理的LINQ中判断日期时间段的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: c# 读取txt方法
- 下一篇: CPU profiling