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. Problem for retriveing record using between for date datetype

Problem for retriveing record using between for date datetype

Scheduled Pinned Locked Moved Database
helpdatabase
5 Posts 3 Posters 5 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
    sishya
    wrote on last edited by
    #1

    Hi , pls help me out with this code insert into chk values('notwking',convert(datetime,getdate(),101)) the row gets inserted into the table(type varchar, type datetime). but if i try to retrive that record by this query select * from chk where dt between getdate() and getdate()+20 i dont get that tuple but i get the same with this query select * from chk where dt between getdate()-1 and getdate()+20 i thnk the problem is with the time part which is inserted during insertion. is there any solution.Pls help me out Thnks in advance

    E V 2 Replies Last reply
    0
    • S sishya

      Hi , pls help me out with this code insert into chk values('notwking',convert(datetime,getdate(),101)) the row gets inserted into the table(type varchar, type datetime). but if i try to retrive that record by this query select * from chk where dt between getdate() and getdate()+20 i dont get that tuple but i get the same with this query select * from chk where dt between getdate()-1 and getdate()+20 i thnk the problem is with the time part which is inserted during insertion. is there any solution.Pls help me out Thnks in advance

      E Offline
      E Offline
      Edbert P
      wrote on last edited by
      #2

      Always use DateDiff when working with date. Syntax: DATEDIFF([datepart], [firstdate], [seconddate]) where datepart can be day, month, year, etc. Example:

      WHERE DATEDIFF( dd, GETDATE(), @myDate )
      BETWEEN DATEDIFF( dd, GETDATE(), @dateFrom )
      AND DATEDIFF( dd, GETDATE(), @dateTo )

      Does that help? "Democracy is two wolves and a sheep voting on what to have for dinner" - Ross Edbert Sydney, Australia

      1 Reply Last reply
      0
      • S sishya

        Hi , pls help me out with this code insert into chk values('notwking',convert(datetime,getdate(),101)) the row gets inserted into the table(type varchar, type datetime). but if i try to retrive that record by this query select * from chk where dt between getdate() and getdate()+20 i dont get that tuple but i get the same with this query select * from chk where dt between getdate()-1 and getdate()+20 i thnk the problem is with the time part which is inserted during insertion. is there any solution.Pls help me out Thnks in advance

        V Offline
        V Offline
        vivek g
        wrote on last edited by
        #3

        try this out ... i.e. insert into chk values('notwking',convert(char,getdate(),105) the time part will be removed. vivek

        S 1 Reply Last reply
        0
        • V vivek g

          try this out ... i.e. insert into chk values('notwking',convert(char,getdate(),105) the time part will be removed. vivek

          S Offline
          S Offline
          sishya
          wrote on last edited by
          #4

          Hi, thks fr the advice but insert into chk values('notwking',convert(char,getdate(),105) is actually trying to insert char datatype into datetime field right. regards -- modified at 5:25 Wednesday 21st June, 2006

          V 1 Reply Last reply
          0
          • S sishya

            Hi, thks fr the advice but insert into chk values('notwking',convert(char,getdate(),105) is actually trying to insert char datatype into datetime field right. regards -- modified at 5:25 Wednesday 21st June, 2006

            V Offline
            V Offline
            vivek g
            wrote on last edited by
            #5

            hi, obviously yessssss.............. vivek 9868079257 delhi vivek

            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