Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. Date filtering issues in Linq Query

Date filtering issues in Linq Query

Scheduled Pinned Locked Moved ASP.NET
csharpdatabaselinq
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    V Senthil
    wrote on last edited by
    #1

    Hi, Im facing the probelm in filtering the record using the date criteria. Im having 2 column FromDate and ToDate. Eg: FromDate : 28/04/2011 & ToDate : 11/03/2012 If i pass the FromDate as 04/09/2011 and ToDate as 10/09/2011 means i need to get the above the record, but i cant able to the data. Query i used date criteria: ------------------------------ [FromDate] >= FromDate.Value && [FromDate] <= ToDate.Value && [ToDate] >= FromDate.Value && [ToDate] <= ToDate.Value Can i know the pblm in the above query. Thanks, Senthil V.

    M J 2 Replies Last reply
    0
    • V V Senthil

      Hi, Im facing the probelm in filtering the record using the date criteria. Im having 2 column FromDate and ToDate. Eg: FromDate : 28/04/2011 & ToDate : 11/03/2012 If i pass the FromDate as 04/09/2011 and ToDate as 10/09/2011 means i need to get the above the record, but i cant able to the data. Query i used date criteria: ------------------------------ [FromDate] >= FromDate.Value && [FromDate] <= ToDate.Value && [ToDate] >= FromDate.Value && [ToDate] <= ToDate.Value Can i know the pblm in the above query. Thanks, Senthil V.

      M Offline
      M Offline
      Morgs Morgan
      wrote on last edited by
      #2

      Firstly, looking at those square brackets on table column names, it appears to me this T-SQL not Linq as you say it is? If it is T-SQL here goes it:

      "SELECT \* FROM \[Table\] WHERE \[FromDate\] >= '" + FromDate.Value  + "' AND \[ToDate\] <= '" + ToDate.Value + "';"
      

      Otherwise if it's indeed Linq-SQL then try this:

      var myTableData = dataContextInstance.MyTable.Where( e => e.FromDate >= DateTime.Parse( FromDate.Value ) && e.ToDate <= DateTime.Parse( ToDate.Value ) ).ToList();

      //This will simply return a list or data matching your linq-query and there are many ways you can loop through a list e.g. for-loop, each loop

      hope this will help otherwise clarify a little on ya question. Morgs

      1 Reply Last reply
      0
      • V V Senthil

        Hi, Im facing the probelm in filtering the record using the date criteria. Im having 2 column FromDate and ToDate. Eg: FromDate : 28/04/2011 & ToDate : 11/03/2012 If i pass the FromDate as 04/09/2011 and ToDate as 10/09/2011 means i need to get the above the record, but i cant able to the data. Query i used date criteria: ------------------------------ [FromDate] >= FromDate.Value && [FromDate] <= ToDate.Value && [ToDate] >= FromDate.Value && [ToDate] <= ToDate.Value Can i know the pblm in the above query. Thanks, Senthil V.

        J Offline
        J Offline
        Jassim Makki
        wrote on last edited by
        #3

        Hi, Try to reverse the comparissons and see what happens ;)

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups