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. General Programming
  3. LINQ
  4. hi i'm having problem with linq query datetime...

hi i'm having problem with linq query datetime...

Scheduled Pinned Locked Moved LINQ
databasehelpcsharplinqtutorial
5 Posts 2 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.
  • A Offline
    A Offline
    amalatsliit
    wrote on last edited by
    #1

    hi i'm having problem with linq query... this is what i have var query = from venue in db.Venues select venue; query = query.Where(q =>; SqlMethods.DateDiffDay(q.ExpiresDate, DateTime.Now) == 7); query = query.Where(q =>; q.IsDisplay).OrderByDescending(q =>; q.ExpiresDate); what i want is to populate venues which are expired 7 days from todate..but date formats are different of q.ExpiresDate and DateTime.Now. how to solve this problem...is thr anyway that i can format datetime.now to expiredatetime... need help urgetly...

    J 1 Reply Last reply
    0
    • A amalatsliit

      hi i'm having problem with linq query... this is what i have var query = from venue in db.Venues select venue; query = query.Where(q =>; SqlMethods.DateDiffDay(q.ExpiresDate, DateTime.Now) == 7); query = query.Where(q =>; q.IsDisplay).OrderByDescending(q =>; q.ExpiresDate); what i want is to populate venues which are expired 7 days from todate..but date formats are different of q.ExpiresDate and DateTime.Now. how to solve this problem...is thr anyway that i can format datetime.now to expiredatetime... need help urgetly...

      J Offline
      J Offline
      J4amieC
      wrote on last edited by
      #2

      why are you not doing the whole query as LINQ?

      var query = from venue in db.venues
      where venue.IsDisplay && DateTime.Now.Subtract(venue.ExpiresDate).TotalDays == 7
      select venue;

      A 2 Replies Last reply
      0
      • J J4amieC

        why are you not doing the whole query as LINQ?

        var query = from venue in db.venues
        where venue.IsDisplay && DateTime.Now.Subtract(venue.ExpiresDate).TotalDays == 7
        select venue;

        A Offline
        A Offline
        amalatsliit
        wrote on last edited by
        #3

        hey J4amiec thankx for reply.i hv tried u r solution bt it gives this error Method 'System.TimeSpan Subtract(System.DateTime)' has no supported translation to SQL. ....

        J 1 Reply Last reply
        0
        • J J4amieC

          why are you not doing the whole query as LINQ?

          var query = from venue in db.venues
          where venue.IsDisplay && DateTime.Now.Subtract(venue.ExpiresDate).TotalDays == 7
          select venue;

          A Offline
          A Offline
          amalatsliit
          wrote on last edited by
          #4

          finally manage to get done the work...maybe this is nt the correct way bt it works fine... var query = from venue in db.Venues where ((venue.ExpiresDate < DateTime.Today.AddDays(1).Date && venue.ExpiresDate > DateTime.Today.AddDays(-2).Date) || (venue.ExpiresDate < DateTime.Today.AddDays(7).Date && venue.ExpiresDate > DateTime.Today.AddDays(5).Date)) && venue.IsDisplay select venue;

          1 Reply Last reply
          0
          • A amalatsliit

            hey J4amiec thankx for reply.i hv tried u r solution bt it gives this error Method 'System.TimeSpan Subtract(System.DateTime)' has no supported translation to SQL. ....

            J Offline
            J Offline
            J4amieC
            wrote on last edited by
            #5

            Sorry, I don't speak txtspk.

            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