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



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#
Posted
Comments
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    
DateTime

1 solution

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

in your linq statement
C#
dates = System.Data.Objects.SqlClient.SqlFunctions.DateDiff("dd", n.CreatedDateTime, now)
 
Share this answer
 
v2
Comments
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