Between Noon today and Noon tomorrow?

Discussion in 'microsoft.public.sqlserver.programming' started by Jason, Dec 1, 2004.

  1. Jason

    Jason Guest

    I am trying to write a query that will pull records with a particular
    date between Noon today and Noon Tomorrow. Can anyone please help
    with some ideas.

    Thanks
     
    Jason, Dec 1, 2004
    #1
    1. Advertisements

  2. DECLARE @sd SMALLDATETIME

    SET @sd = DATEADD(HOUR, 12, CONVERT(CHAR(8), GETDATE(), 112))

    SELECT [columns] FROM [table]
    WHERE [dtColumn] >= @sd
    AND [dtColumn] < (@sd + 1)

    (Maybe you want to include the rows from noon tomorrow, in which case,
    change < to <= )
     
    Aaron [SQL Server MVP], Dec 1, 2004
    #2
    1. Advertisements

  3. Jason

    Anith Sen Guest

    See DATEADD, DATEPART & DATEDIFF functions in SQL Server Books Online. With
    these and perhaps some other functions, you should be able to come up with a
    logic to extract the data you need.
     
    Anith Sen, Dec 1, 2004
    #3
  4. Here's one way:

    SELECT *
    FROM YourTable
    WHERE DateCol BETWEEN DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 0.5)
    AND DATEADD(dd, DATEDIFF(dd, 0, GETDATE()), 1.5)
     
    Adam Machanic, Dec 1, 2004
    #4
  5. SELECT <column list>
    FROM <table>
    WHERE <datetime column> >= DATEADD(hh, 12, CONVERT(CHAR(8), GETDATE(), 112))
    AND <datetime column> < DATEADD(hh, 36, CONVERT(CHAR(8), GETDATE(), 112))
     
    Jacco Schalkwijk, Dec 1, 2004
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.