[英]Best way to compare two date(data is string type) in linq c#
我想比较下面的代码在LINQ C#中的两个日期(数据是字符串类型)。
var checkStoreClose = (from s in database.STORE
where s.StoreClose_DT < txt_inputDateFromUser
select s);
// s.StoreClose_DT is string "08-Sep-2017"
// txt_inputDateFromUser is string "09-Sep-2017"
我想我应该做的步骤如下:
你能建议我吗?
在这里,日期转换发生在客户端。
var inputDate = DateTime.Parse(txt_inputDateFromUser);
var checkStoreClose = (from s in database.STORE
where DateTime.Parse(s.StoreClose_DT) < inputDate
select s);
你可以这样做:
var checkStoreClose = (from s in database.STORE
where DateTime.Parse(s.StoreClose_DT) < DateTime.Parse(txt_inputDateFromUser)
select s);
DateTime dtBusinessDate;
DateTime dtStoreClosedDate;
if (DateTime.TryParseExact(txt_inputDateFromUser.Value, "d-MMM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dtBusinessDate) && DateTime.TryParseExact(getStoreCloseDT, "d-MMM-yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out dtStoreClosedDate))
{
if (dtBusinessDate > dtStoreClosedDate)
{
...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.