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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Database & SysAdmin
  3. Database
  4. current date query

current date query

Scheduled Pinned Locked Moved Database
database
8 Posts 4 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.
  • P Offline
    P Offline
    Pankaj Garg
    wrote on last edited by
    #1

    SELECT Dat FROM dbo.tblkmreading WHERE DAT = GETDATE() i have records pertaining to current date , the above query is not fetching the records.Please rectify it

    If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!

    A A 2 Replies Last reply
    0
    • P Pankaj Garg

      SELECT Dat FROM dbo.tblkmreading WHERE DAT = GETDATE() i have records pertaining to current date , the above query is not fetching the records.Please rectify it

      If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!

      A Offline
      A Offline
      Andy_L_J
      wrote on last edited by
      #2

      Thie GETDATE() Function returns the time now ie: 3/30/2008 12.35.05... You will need to parse the GETDATE() result to return just MM/DD/YYYY and use his in your WHERE clause.

      I don't speak Idiot - please talk slowly and clearly

      P 1 Reply Last reply
      0
      • A Andy_L_J

        Thie GETDATE() Function returns the time now ie: 3/30/2008 12.35.05... You will need to parse the GETDATE() result to return just MM/DD/YYYY and use his in your WHERE clause.

        I don't speak Idiot - please talk slowly and clearly

        P Offline
        P Offline
        Pankaj Garg
        wrote on last edited by
        #3

        select dat from tblkmreading where dat = convert(varchar(10) , getdate() , 103) still getting the following error The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. dat is a datetime type this is the another way i did , but no record is comming select dat from tblkmreading where dat = convert(datetime , getdate() , 103)

        If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!

        A 1 Reply Last reply
        0
        • P Pankaj Garg

          SELECT Dat FROM dbo.tblkmreading WHERE DAT = GETDATE() i have records pertaining to current date , the above query is not fetching the records.Please rectify it

          If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!

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

          Try this declare @Now datetime select @Now = convert(varchar,getdate(),103) SELECT Dat FROM dbo.tblkmreading WHERE DAT >= @Now I suspect your Dat column contains a time as well as a date. The above code trims off the time from getdate.

          Bob Ashfield Consultants Ltd

          P 1 Reply Last reply
          0
          • A Ashfield

            Try this declare @Now datetime select @Now = convert(varchar,getdate(),103) SELECT Dat FROM dbo.tblkmreading WHERE DAT >= @Now I suspect your Dat column contains a time as well as a date. The above code trims off the time from getdate.

            Bob Ashfield Consultants Ltd

            P Offline
            P Offline
            Pankaj Garg
            wrote on last edited by
            #5

            dat is of datetime type still occuring the error The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

            If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!

            A 1 Reply Last reply
            0
            • P Pankaj Garg

              select dat from tblkmreading where dat = convert(varchar(10) , getdate() , 103) still getting the following error The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value. dat is a datetime type this is the another way i did , but no record is comming select dat from tblkmreading where dat = convert(datetime , getdate() , 103)

              If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!

              A Offline
              A Offline
              Andy_L_J
              wrote on last edited by
              #6

              Is the data stored as DateTime dataType in the database? You cant expect that your query will run at the exact time that a record is written. In this case you may have to change your Where clause to BETWEEN and look from 12:00:00am to 11:59:00pm. Or Between 3/31/2002 12:00:00 And 4/1/2008 12:00:00 Sorry, I dont have a query editor handy to check this out :( DECLARE @Start DateTime SET @Start = '3/31/2008' DECLARE @End DateTime SET @End = '4/1/2008' SELECT [Date] FROM TestData Where [Date] Between @Start and @End

              I don't speak Idiot - please talk slowly and clearly

              1 Reply Last reply
              0
              • P Pankaj Garg

                dat is of datetime type still occuring the error The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.

                If you have an apple & I have an apple and we exchange our apples, then each of us will still have only one apple but if you have an idea & I have an idea and we exchange our ideas, then each of us will have two ideas!

                A Offline
                A Offline
                Ashfield
                wrote on last edited by
                #7

                What version of SQL Server are you using? My code works fine with 2000 and 2005.

                Bob Ashfield Consultants Ltd

                S 1 Reply Last reply
                0
                • A Ashfield

                  What version of SQL Server are you using? My code works fine with 2000 and 2005.

                  Bob Ashfield Consultants Ltd

                  S Offline
                  S Offline
                  Sankar Komma
                  wrote on last edited by
                  #8

                  If Dat is date time format in your table then use following query SELECT Dat FROM dbo.tblkmreading WHERE convert(varchar,Dat,103) = convert(varchar,GETDATE(),103) If Dat is varchar in your table then use following query SELECT Dat FROM dbo.tblkmreading WHERE convert(varchar,convert(datetime,Dat),103) = convert(varchar,GETDATE(),103)

                  smile :-)

                  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