Solved

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

Posted on 2011-02-23
1
897 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 63

Accepted Solution

by:
Fernando Soto earned 500 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Generate Unique ID in VB.NET 21 137
Filtering a datagrid view 8 46
Send SMS from vb.net desktop app 30 53
How to embed a manual into my vb 2005 project 7 26
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

710 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