LINQ - Convert in where clause - Asked By Shan on 03-May-11 09:51 AM

Hi,

 I have a datetime column I want to fetch all the data for a particular date how to use convert in where condition
dipa ahuja replied to Shan on 03-May-11 09:55 AM
you can use date data same like string means using single quotes

string q = "select * from users where  orderdate>='1/1/2026'";


Reena Jain replied to Shan on 03-May-11 09:58 AM
Hi,

You can extract just the 'date' portion of a DateTime as follows:

ob.CreatedDate.Date == Convert.ToDateTime(createdDate).Date

Hope this will help you
TSN ... replied to Shan on 03-May-11 10:00 AM


hi..


use in the below format..

classes = classes.Where(cls => Convert.ToDateTime("1/1/2026 " )
Sahil Kumar replied to Shan on 03-May-11 10:03 AM
Hi,

You can use this

var result=from qry in "some collection or sql" where qry>5 order by qry select qry;

I hope this will help you.
Renjith Maxy replied to Shan on 06-May-11 01:45 AM
Hope the following Query get the appropriate result for you.

var result = ( From Variable in Collection where Variable.Date== YourPerticularDate select Variable).ToList();
Renjith Maxy replied to Renjith Maxy on 06-May-11 01:51 AM
Sorry I am new to this site so  i didn't find the edit option to edit my posted tag so i am posting once more please bare with me

var result = ( From Variable in Collection where Variable.Date== Convert.ToDateTime (YourPerticularDate) select Variable).ToList();
Jitendra Faye replied to Shan on 13-May-11 01:14 AM
For this you have to convert both value in datatime type-

use this code-

 List<Order> result = (from obj in _list

                  where (DateTime)obj.DespatchDate >= Convert.ToDateTime (txtDate.Text) 
              select obj).ToList();

try and let me know.