Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Time only portion of the date to use in LINQ query
Message
 
General information
Forum:
ASP.NET
Category:
LINQ
Environment versions
Environment:
C# 4.0
OS:
Windows 7
Network:
Windows 2003 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01622912
Message ID:
01622917
Views:
105
Can not yet make it to work. That's my latest attempt which blows up in run-time:
 var startTime = new DateTime(1900, 1, 1, beginDateTime.Hour, beginDateTime.Minute, 0);
                var endTime = new DateTime(1900, 1, 1, endDateTime.Hour, endDateTime.Minute, 0);
                var daysOfWeek = dailyLimits.Where(dl => dl.Selected == true).Select(ds => ds.WeekDay).ToList();
                if (daysOfWeek.Count() < 7) // not all days of the week selected
                {
                    query = query.Where(m4s => DateTime.Parse("01-01-1900 " + m4s.StartTime.Value.ToShortTimeString()) <= endTime &&
                    DateTime.Parse("01-01-1900 " + m4s.EndTime.Value.ToShortTimeString()) >= startTime && daysOfWeek.Contains((short)m4s.StartTime.Value.DayOfWeek));
                }
about the Parse problem. Has anyone deal with this problem already of getting time portion of the date using LINQ?

Thanks in advance.

UPDATE. Tried TimeOfDay and it worked in my quick test, but the code it produced is not a clear conversion to time as I hoped. Still looking for better solutions.
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform