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. Can't search through Date

Can't search through Date

Scheduled Pinned Locked Moved Database
questiondatabasehelp
6 Posts 5 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.
  • G Offline
    G Offline
    Gamzun
    wrote on last edited by
    #1

    im using this query select date from table where date='5/7/2007' it returns '0' rows, but when I run this follwoing query it returns 2 rows select date from table where date='5/7/2007 1:30:00 PM' i don't want to search with time how can i do that? i even try this select date from table where date='5/7/2007%' but it gives error as it cant convert smalldatetime to string any solution.

    L M P 3 Replies Last reply
    0
    • G Gamzun

      im using this query select date from table where date='5/7/2007' it returns '0' rows, but when I run this follwoing query it returns 2 rows select date from table where date='5/7/2007 1:30:00 PM' i don't want to search with time how can i do that? i even try this select date from table where date='5/7/2007%' but it gives error as it cant convert smalldatetime to string any solution.

      L Offline
      L Offline
      leckey 0
      wrote on last edited by
      #2

      http://sqlserver2000.databases.aspfaq.com/can-i-make-sql-server-format-dates-and-times-for-me.html[^] I've used this reference for formating in the past. Hope it helps.

      __________________ Bob is my homeboy.

      1 Reply Last reply
      0
      • G Gamzun

        im using this query select date from table where date='5/7/2007' it returns '0' rows, but when I run this follwoing query it returns 2 rows select date from table where date='5/7/2007 1:30:00 PM' i don't want to search with time how can i do that? i even try this select date from table where date='5/7/2007%' but it gives error as it cant convert smalldatetime to string any solution.

        M Offline
        M Offline
        Mike Dimmick
        wrote on last edited by
        #3

        Everyone seems to be doing this today! Firstly - use ISO 8601 format. This format - yyyyMMdd - is not subject to misinterpretation by different locale settings. Secondly, dates have a time part. If you want any time on 7 May 2007, use:

        WHERE date >= '20070507' AND date < '20070508'

        If you don't specify a time part for a date literal, the time part is set to 00:00:00 (i.e. 12am).

        Stability. What an interesting concept. -- Chris Maunder

        G 1 Reply Last reply
        0
        • M Mike Dimmick

          Everyone seems to be doing this today! Firstly - use ISO 8601 format. This format - yyyyMMdd - is not subject to misinterpretation by different locale settings. Secondly, dates have a time part. If you want any time on 7 May 2007, use:

          WHERE date >= '20070507' AND date < '20070508'

          If you don't specify a time part for a date literal, the time part is set to 00:00:00 (i.e. 12am).

          Stability. What an interesting concept. -- Chris Maunder

          G Offline
          G Offline
          Gamzun
          wrote on last edited by
          #4

          Thanks Mike, I'll be much oblige if you can tell me how to set that format? n where should set this ISO format either in OS or MSSQL Management Studio? Thanks Again

          R 1 Reply Last reply
          0
          • G Gamzun

            Thanks Mike, I'll be much oblige if you can tell me how to set that format? n where should set this ISO format either in OS or MSSQL Management Studio? Thanks Again

            R Offline
            R Offline
            Rob Graham
            wrote on last edited by
            #5

            gamzun wrote:

            n where should set this ISO format either in OS or MSSQL Management Studio?

            YOU must employ the format in YOUR application / queries. This is not an OS or Server task. It is up to the application to format user entered dates properly before submitting them to the server in queries....

            1 Reply Last reply
            0
            • G Gamzun

              im using this query select date from table where date='5/7/2007' it returns '0' rows, but when I run this follwoing query it returns 2 rows select date from table where date='5/7/2007 1:30:00 PM' i don't want to search with time how can i do that? i even try this select date from table where date='5/7/2007%' but it gives error as it cant convert smalldatetime to string any solution.

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

              Use convert statement to the format required and use style 105 to cut date... Remember to convert date to the table format while selecting... '%' Sign can be used only with a string and if ur date format in the table is datetime then that cant be done

              PPK

              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