how to write linq query for comparing date between start & end date


  • hi Team,

    autally my reqiurement is that i can selected start and end dates from DatePicker and i have to compare them such way i.e,

    all records records comes in between them are show in datagrid.

    my all records are presented in obserable collection list(my list name is ladlelist)

    pls send me as possible .

    thanks in advance.........................

    Thursday, August 04, 2011 5:44 AM


  • Hi,

    I think you should try this:

    var s = from p in ladlelist where p.lf_start <=(DateTime) (dpkFromDate.SelectedDate.Value??DateTime.MinValue) && p.lf_end >= (DateTime)(dpkToDate.SelectedDate.Value ?? DateTime.MinValue)
    select p;

    Because, the SelectedDate is a nullable datetime, so we can't compare between a DateTime and DateTime? directly.

    Monday, August 08, 2011 2:10 AM

All replies