原文地址(https://blog.csdn.net/yangxinyue315/article/details/44960895)sql
在使用EF時,想要比較字符串類型的日期時,參考如下:json
SQL語句:markdown
1)select * from TableName where StartTime > ‘2015-04-08’
2)select * from TableName where StartTime >= ‘2015-04-08’
3)select * from TableName where StartTime < ‘2015-04-08’
4)select * from TableName where StartTime <= ‘2015-04-08’
lambda表達式寫法:mvc
1).Where(a => a.StartTime.CompareTo(‘2015-04-08’) > 0)
2).Where(a => a.StartTime.CompareTo(‘2015-04-08’) >= 0)
3).Where(a => a.StartTime.CompareTo(‘2015-04-08’) < 0)
4).Where(a => a.StartTime.CompareTo(‘2015-04-08’) <= 0)
更規範的寫法:sqlserver
1).Where(a => String.Compare(a.StartTime, ‘2015-04-08’, StringComparison.Ordinal) > 0)
2).Where(a => String.Compare(a.StartTime, ‘2015-04-08’, StringComparison.Ordinal) >= 0)
3).Where(a => String.Compare(a.StartTime, ‘2015-04-08’, StringComparison.Ordinal) < 0)
4).Where(a => String.Compare(a.StartTime, ‘2015-04-08’, StringComparison.Ordinal) <= 0)post