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. Retrieve records from sqlserver 2005 which are today inserted

Retrieve records from sqlserver 2005 which are today inserted

Scheduled Pinned Locked Moved Database
databasesql-serversysadminquestion
6 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
    sali22
    wrote on last edited by
    #1

    Good day, I want to retrieve records from sql server 2005 that belongs to today, my datatype in sqlserver is : datetime and store date like : 9/5/2012 12:55:26 PM So i want to know how can I write a query to retrieve only today's records. Thanks in advance

    P S S 3 Replies Last reply
    0
    • S sali22

      Good day, I want to retrieve records from sql server 2005 that belongs to today, my datatype in sqlserver is : datetime and store date like : 9/5/2012 12:55:26 PM So i want to know how can I write a query to retrieve only today's records. Thanks in advance

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2
      1. I hope you're using a DATETIME field and not storing dates as strings. Otherwise you're hosed. 1) If this is a recent version of SQL Server you can try WHERE datefield >= CAST(GETDATE() AS DATE)
      1 Reply Last reply
      0
      • S sali22

        Good day, I want to retrieve records from sql server 2005 that belongs to today, my datatype in sqlserver is : datetime and store date like : 9/5/2012 12:55:26 PM So i want to know how can I write a query to retrieve only today's records. Thanks in advance

        S Offline
        S Offline
        sali22
        wrote on last edited by
        #3

        i have found it :) WHERE LASTUPDATEON >= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0) AND LASTUPDATEON < DATEADD(day, DATEDIFF(day, 0, GETDATE()), 1)

        P 1 Reply Last reply
        0
        • S sali22

          i have found it :) WHERE LASTUPDATEON >= DATEADD(day, DATEDIFF(day, 0, GETDATE()), 0) AND LASTUPDATEON < DATEADD(day, DATEDIFF(day, 0, GETDATE()), 1)

          P Offline
          P Offline
          PIEBALDconsult
          wrote on last edited by
          #4

          WTE! :wtf: Which database system? Why would you have to eliminate records that will be updated tomorrow? "Simplify. Simpify." -- Thoreau

          1 Reply Last reply
          0
          • S sali22

            Good day, I want to retrieve records from sql server 2005 that belongs to today, my datatype in sqlserver is : datetime and store date like : 9/5/2012 12:55:26 PM So i want to know how can I write a query to retrieve only today's records. Thanks in advance

            S Offline
            S Offline
            Santhosh Kumar Jayaraman
            wrote on last edited by
            #5

            try this select * from booking where Convert(varchar(20),SaveDate,111)=Convert(varchar(20),GETDATE(),111) here savedate is the column where i need to check.

            P 1 Reply Last reply
            0
            • S Santhosh Kumar Jayaraman

              try this select * from booking where Convert(varchar(20),SaveDate,111)=Convert(varchar(20),GETDATE(),111) here savedate is the column where i need to check.

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              That is very very bad. Highly inefficient. You convert every (millions?) SaveDate value and then do a string compare -- which is much less efficient than the DATETIME compare would be. <anecdote> I once fixed a program that was written that way -- before I fixed it it took forty minutes to run, afterward it took only ten minutes. </anecdote> DON'T EVER DO THAT!! :mad: :mad: :mad: :mad: :mad: :mad:

              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