Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How would I use a TimeSpan Duration in a LINQ Where clause

Posted on 2011-02-23
1
Medium Priority
?
921 Views
Last Modified: 2012-05-11
I have a LINQ statement where I need to find the first row in a dictionary where the difference between a Dictionary item date and a reference time is less than 2 minutes.

 legSlot = (From l As MissionLeg In missionCollection(missionKey)
                 Where l.DestIcao = eventRef.GeoId And 
                (l.DepartTime - eventRef.EventDateTime.AddHours(-eventRef.FlightTime)) < TimeSpan.FromMinutes(2)
                 Select l).FirstOrDefault()

Open in new window


The code above works fine when l.DepartTime is greater than eventRef.EventDateTime.AddHours(-eventRef.FlightTime))

I tried the following modification:

  (l.DepartTime - eventRef.EventDateTime.AddHours(-eventRef.FlightTime)).Value.Duration() < TimeSpan.FromMinutes(2)

Open in new window


But this throws errors.

Is there another way to get the absolute value of the duration between two dates?


0
Comment
Question by:MDKIMZEY
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 64

Accepted Solution

by:
Fernando Soto earned 2000 total points
ID: 34965062
Hi MDKIMZEY;

Try it like this.

legSlot = (From l As MissionLeg In missionCollection(missionKey)
           Where l.DestIcao = eventRef.GeoId And 
                 (TimeSpan.FromTicks(l.DepartTime.Ticks - eventRef.EventDateTime.AddHours(-eventRef.FlightTime).Ticks)) < TimeSpan.FromMinutes(2)
                 Select l).FirstOrDefault()

Open in new window


Fernando
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question