Reputation: 31
How to write a LINQ query to get the records between two timestamps?
I have 3 text boxes for fromdate
, hour
, time
and another 3 text boxes for todate
, hour
, time
.
Codes below results incorrect records. How to get records with date, hours, min wise?
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))
Upvotes: 0
Views: 280
Reputation: 755
It is extremely difficult to understand your query logic.
Why did you choose three different text boxes for collecting date,hour,min.You can simple use one text box which is storing starting DateTime and another one for store ending DateTime.So,No need to specify this much of Textboxes for finding the records between a specific date time.
You can use different dateTime function(s) to do your DateTime conversions as per your requirements.If you want to split Date,hour,min from this Datetime string,then you can simply use C# DateTime helper functions.
Upvotes: 1