Register   |   Login

 

Spark Your Solution

 Scott's Technology Blog Minimize

Dec 7

Written by: Scott Davis
12/7/2008 10:20 PM

Occasionally you have a need to write a SQL query that shows you data that was entered or modified in the past X seconds or minutes.  The time on the computer executing the code could be several minutes off of the time on the database server.  So how do you get the current time in the database in a Linq query?  You can't call the GetDate() or GetUTCDate()  functions within a Linq query so how would you do it?  A quick little hack is to create a view that contains only the two functions, such as

 

Create View dbo.vw_SystemUtcTime
as
Select getdate() as Now, getutcdate() as UtcNow

 

Now drag this view in to the data context designer and you can join your queries to this view, for use in your where clause.

Tags:

Your name:
Title:
Comment:
Add Comment    Cancel  

  
 Blog Dates Minimize

 Print   
 Search Minimize

 Print