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. how to search specific datetime in sql server 2005

how to search specific datetime in sql server 2005

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelptutorial
4 Posts 2 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.
  • H Offline
    H Offline
    harcaype
    wrote on last edited by
    #1

    hi. I'm trying to locate the date/time of a certain data. I've tried the typical "SELECT * FROM this_table WHERE column_name = ''. This does not return anything. Can someone help me with this? I want to search quickly for the specified date and time. Thanks!

    W 1 Reply Last reply
    0
    • H harcaype

      hi. I'm trying to locate the date/time of a certain data. I've tried the typical "SELECT * FROM this_table WHERE column_name = ''. This does not return anything. Can someone help me with this? I want to search quickly for the specified date and time. Thanks!

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Hi, If the data type of column_name is datetime, 'some date' should be convertible to datetime implicitely or you should convert it explicitely. For conversion use CONVERT function. For example:

      column_name = CONVERT(datetime, '2008-09-07 12:02:00', 120)

      Also notice that this is exact match so minutes, seconds and so on must match. Mika

      H 1 Reply Last reply
      0
      • W Wendelius

        Hi, If the data type of column_name is datetime, 'some date' should be convertible to datetime implicitely or you should convert it explicitely. For conversion use CONVERT function. For example:

        column_name = CONVERT(datetime, '2008-09-07 12:02:00', 120)

        Also notice that this is exact match so minutes, seconds and so on must match. Mika

        H Offline
        H Offline
        harcaype
        wrote on last edited by
        #3

        Wow thanks. However, What if I would want to search all records under 2008-09-07?

        W 1 Reply Last reply
        0
        • H harcaype

          Wow thanks. However, What if I would want to search all records under 2008-09-07?

          W Offline
          W Offline
          Wendelius
          wrote on last edited by
          #4

          If you know for sure that the time is always at midnight, then you can use equality like:

          column_name = CONVERT(datetime, '2008-09-07', 105)

          If time portion can vary, use ranges like:

          ... column_name >= CONVERT(datetime, '2008-09-07', 105)
          AND column_name < CONVERT(datetime, '2008-09-08', 105)

          Hope this helps, Mika

          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