Click here to Skip to main content
15,667,885 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)

i want to count no of days,when the record is inserted to db with today for every record and want to assign those value to the repeator using linq and c#
DamithSL 26-May-14 9:02am    
update the question with your current linq statement and what have you tried? any exceptions?
Member 10226004 26-May-14 9:04am    
dates =DateTime.Now.Subtract(n.CreatedDateTime.Value.Date).Days

Time span conversion error and want to display in repeator
DamithSL 26-May-14 9:09am    
what is the type of CreatedDateTime? and provide full LINQ statement, what is n here?
Member 10226004 26-May-14 9:11am    

1 solution

define now as current date before the linq statement
DateTime now = DateTime.Now;

in your linq statement
dates = System.Data.Objects.SqlClient.SqlFunctions.DateDiff("dd", n.CreatedDateTime, now)
Share this answer
Member 10226004 26-May-14 9:33am    
am getting SqlFunctions doesnt exist
Member 10226004 26-May-14 9:33am    
is there any code for sqlFunctions
DamithSL 26-May-14 9:46am    
it is on System.Data.Entity dll, you need to add using statement like below
using System.Data.Objects.SqlClient;
Member 10226004 26-May-14 9:57am    
it's working,TnQ

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900