Code Example for Add DateTime and TimeSpan in EF query


I am looking for a code example of this question.

<a href="https://stackoverflow.com/questions/16781587/using-datetime-addtimespan-with-linq" rel="nofollow">Using DateTime.Add(TimeSpan) with LINQ</a>

I need to add an entire TimeSpan to a DateTime.

I already have tried SqlFunctions.DateAdd("ss", SqlFunctions.DatePart("s", b.duration) but this looks like it is only adding the the seconds part of the TimeSpan.

This is the code I have so far

var queryClash = from b in db.calEvents where (newEvent.startTime <= (SqlFunctions.DateAdd("ss", SqlFunctions.DatePart("ss", b.duration), b.startTime))) && (newEventEndTime >= b.startTime) select b;


As suggested in the comments I used:

DbFunctions.AddMilliseconds(b.startTime, DbFunctions.DiffMilliseconds(b.duration, TimeSpan.Zero)) >= endtime)


  • sqlfunctions.checksum of linq object
  • Concatenate Int to String in LINQ Query
  • Comparing DateTime in Entity Framework with an Sql Server Compact database
  • Select Distinct in Access? Syntax error
  • Delete records based on dates
  • convert int values to datetime in sql server
  • How to add hours to date using LINQ query?
  • Rolling 12 Month sum in PowerPivot
  • Get Quarters StartDate and EndDate from Year
  • How can I write a where clause in SQL to filter a DATETIME column by the time of day?
  • html5 tag support
  • Passing variable into xp_cmdshell
  • Running sp_executesql query expects parameter @statement
  • How to parsing NSDate to RFC 822 always use in English?
  • date: illegal option — d, Find difference between two dates
  • Implicit property animations do not work with CAReplicatorLayer?
  • jQueryUI dialog replacement for confirm?
  • Are there “Dynamic Playlists” of unit tests in Visual Studio?
  • Appium MobileElement swipe returns unknown server error
  • How do I include a SWC in an AS2 Flash project?
  • How to add a focus style to an editable ComboBox in WPF
  • Extract zip entries to another Zip file
  • How do I superscript characters in a UIButton?
  • print() is showing quotation marks in results
  • ActiveRecord query for a count of new users by day
  • Q promise. Difference between .when and .then
  • Illegal mix of collations for operation for date/time comparison
  • Is my CUDA kernel really runs on device or is being mistekenly executed by host in emulation?
  • What is Eclipse's Declaration View used for?
  • Microsoft Visual Studio Community 2015 always crashes in Windows 10 if swithed to Visual FoxPro
  • Jquery - Jquery Wysiwyg return html as a string
  • SVN: Merging two branches together
  • retrieve vertices with no linked edge in arangodb
  • Angular 2 constructor injection vs direct access
  • Java static initializers and reflection
  • Android Google Maps API OnLocationChanged only called once
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Append folder name and increment by 1 using batch script
  • UserPrincipal.Current returns apppool on IIS
  • How can I use threading to 'tick' a timer to be accessed by other threads?