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. Select by date

Select by date

Scheduled Pinned Locked Moved Database
question
4 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
    Sam Heller
    wrote on last edited by
    #1

    Hi, I am trying to get results where the parameter that is passed is a date. I am only passing the date itself and not the time although the field in the datebase holds both. How can I retreve date specific results and ignore the time. I currently have WHERE E.Start = @Date But it seems to be passing @Date with the time 00:00:00 at the end which obviously makes the wrong, if any, results comeback. Any ideas appreciated. Thanks

    M T 2 Replies Last reply
    0
    • S Sam Heller

      Hi, I am trying to get results where the parameter that is passed is a date. I am only passing the date itself and not the time although the field in the datebase holds both. How can I retreve date specific results and ignore the time. I currently have WHERE E.Start = @Date But it seems to be passing @Date with the time 00:00:00 at the end which obviously makes the wrong, if any, results comeback. Any ideas appreciated. Thanks

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

      SQL Server does not have a data type which only holds date information, only ones which hold date and time information. In practice if you want any time on a specific day you have to say:

      WHERE E.Start >= @Date AND E.Start < DATEADD( d, 1, @Date )

      Stability. What an interesting concept. -- Chris Maunder

      S 1 Reply Last reply
      0
      • M Mike Dimmick

        SQL Server does not have a data type which only holds date information, only ones which hold date and time information. In practice if you want any time on a specific day you have to say:

        WHERE E.Start >= @Date AND E.Start < DATEADD( d, 1, @Date )

        Stability. What an interesting concept. -- Chris Maunder

        S Offline
        S Offline
        Sam Heller
        wrote on last edited by
        #3

        Yeah I was stupid enough to post without looking three post down where the answer was already written. I came up with something pretty much like you suggested DECLARE @FromDate datetime DECLARE @ToDate datetime SET @FromDate = (CAST(@Date AS datetime )) SET @ToDate = DATEADD( D, 1, (DATEADD(mi, -1, @FromDate )) ) SELECT E.ID As EventID, ET.ID As TypeID, E.Title As EventTitle, V.ID As VenueID, V.[Name] As VenueName, E.Description As EventDescription, E.Start As EventStart, E.Finish As EventFinish FROM Events E INNER JOIN Venues V ON E.VenueID = V.ID INNER JOIN EventTypes ET ON E.TypeID = ET.ID WHERE E.Start >= @FromDate AND E.Start <= @ToDate AND V.CityID = @CityID Thanks anyways

        1 Reply Last reply
        0
        • S Sam Heller

          Hi, I am trying to get results where the parameter that is passed is a date. I am only passing the date itself and not the time although the field in the datebase holds both. How can I retreve date specific results and ignore the time. I currently have WHERE E.Start = @Date But it seems to be passing @Date with the time 00:00:00 at the end which obviously makes the wrong, if any, results comeback. Any ideas appreciated. Thanks

          T Offline
          T Offline
          Thomas Chester
          wrote on last edited by
          #4

          You have two options of rephrasing your WHERE clause. Each solution assumes that both @Date and E.Start are declard as DATETIME: (1) WHERE E.Start BETWEEN @Date AND DATEADD(d, 1, @Date) This will look for E.Start values between midnight on @Date and midnight on @Date + 1 day (2) WHERE DAY(E.Start) = DAY(@Date) AND MONTH(E.Start) = MONTH(@Date) AND YEAR(E.Start) = YEAR(@Date) This will explicitly compare the month, day, and year components of each field and only flag those where all three are the same.

          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