[英]LINQ query to fetch the records between the date and time
如何编写LINQ查询以获取两个时间戳之间的记录?
我有3个用于fromdate
, hour
, time
文本框,另外3个用于todate
, hour
, time
文本框。
下面的代码导致记录不正确。 如何获取日期,小时,分钟的记录?
int Fromhours = FHrs;
int Tohours = ToHrs;
int From_min = FromMin;
int To_min = ToMin;
var items = Pirs.Where(a => !a.dataFrame.EndsWith("AAAAAAAAAAA=")
&& (fromDate == null ||
fromDate.Value.Date <= TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(a.timestamp),
TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).Date)
&& ((toDate == null ||
toDate.Value.Date >= TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(a.timestamp),
TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).Date)
&& fromDate == null ||
TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(a.timestamp),
TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).Hour >= Fromhours
&& fromDate == null ||
TimeZoneInfo.ConvertTimeFromUtc(Convert.ToDateTime(a.timestamp),
TimeZoneInfo.FindSystemTimeZoneById("India Standard Time")).Hour <= Tohours))
很难理解您的查询逻辑。
为什么要选择三个不同的文本框来收集日期,小时,分钟。您可以简单地使用一个文本框来存储开始日期时间,另一个文本框来存储结束日期时间。因此,无需指定这么多的文本框来查找记录在特定日期时间之间。
您可以根据需要使用不同的dateTime函数进行DateTime转换。如果要从此Datetime字符串中拆分Date,hour,min,则可以简单地使用C#DateTime辅助函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.