Click here to Skip to main content
15,064,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,


In my old version of my project i have to used to retrieve records from SQL using the following SQL Query

where Convert(date,<DBCOLUMNNAME>,101) between Convert(date,<DATETIME VARIABLE>,101) and Convert(date,<DATETIME VARIABLE>,101) 


Above SQL Query fetch records what we expect,
For example

where Convert(date,FollowupDate,101) between Convert(date,'12/10/2012 12:00:00 AM',101) and Convert(date,'12/10/2012 12:00:00 AM',101) 


The result will be,
Records with FollowupDate = '12/10/2012' (MM/dd/yyyy)

Now we are using linq ,
Here the same SQL is converted as

Quote:
LeadDataContext ds = new LeadDataContext();
DateTime fd = DateTime.ParseExact("12/10/2012","MM/dd/yyyy",null);

var g = from a in ds.Leads
where a.FollowupDate >= fd.Date && a.FollowupDate <= fd.Date
select a;



But Its not retrieving the record while i search on particular date(12/10/2012)(both are same dates)

I have found in my DB, the FollowupDate is stored as '
2012-12-10 10:00:00.000


but i need to check without timestamp hence i need to convert 'Followupdate' column without timestamp as like i did in above SQL query.

Even i checked with variable "fd" it retrieves "12/10/2012 12:00:00 AM" hence i tried to convert "fd" as "12/10/2012 00:00:00" but its not works..


Please help me out.. I'm newer to LINQ forgive me if i made some mistake in Syntax
Posted
Updated 10-Dec-12 20:25pm
v2

1 solution

I found the solution myself,

I posted it here for my Juniors..

i should use syntax of linq as

where a.FollowupDate.Value.Date >= fd.Date && a.FollowupDate.Value.Date <= fd.Date



Both sides of equal are having same Property here(Date), hence it compares '12/10/2012 12:00:00 AM' >= '12/10/2012 12:00:00 AM' hence it retrieves.
   

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