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. Database & SysAdmin
  3. Database
  4. Selecting records of last two days:

Selecting records of last two days:

Scheduled Pinned Locked Moved Database
databasehelp
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.
  • S Offline
    S Offline
    Shahzad Aslam
    wrote on last edited by
    #1

    Hi I want to select records from last two days, the following query does not return any record. select * from tablename where datefield = dateadd(day,-2,Getdate()) Any help will be appreciated.

    Shahzad Aslam Software Engineer

    C B 2 Replies Last reply
    0
    • S Shahzad Aslam

      Hi I want to select records from last two days, the following query does not return any record. select * from tablename where datefield = dateadd(day,-2,Getdate()) Any help will be appreciated.

      Shahzad Aslam Software Engineer

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      The = sign is your problem. Try >=, otherwise you're only asking for records that have exactly the same time as today, but two days ago.

      Christian Graus - Microsoft MVP - C++ "I am working on a project that will convert a FORTRAN code to corresponding C++ code.I am not aware of FORTRAN syntax" ( spotted in the C++/CLI forum )

      1 Reply Last reply
      0
      • S Shahzad Aslam

        Hi I want to select records from last two days, the following query does not return any record. select * from tablename where datefield = dateadd(day,-2,Getdate()) Any help will be appreciated.

        Shahzad Aslam Software Engineer

        B Offline
        B Offline
        bablu_singh
        wrote on last edited by
        #3

        Try the following solutions: 1) use the abbreviations 'd' OR 'dd' inplace of day in your syntax. 2) Check out your table. Are you storing your data alongiwth the time in the database. If yes then this query will never return any result Thanks, Vikash Kumar Singh

        vikash

        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