Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6148907
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T19:21:41+00:00 2026-05-23T19:21:41+00:00

How can I use the SQL DATEADD() function to find a record from this

  • 0

How can I use the SQL DATEADD() function to find a record from this business day? For example:

SELECT * FROM records r
WHERE r.creationTime <= GETDATE()
  AND r.creationTime >= DATEADD(dd, -1 * hoursFromStartOfThisDay, GETDATE())

Where ‘hoursFromStartOfThisDay’ is exactly what it says.

Note: I’m talking about business days so from 9am-5pm, Monday-Friday if that matters at all.

Thanks, guys!

Edit: I am also looking to apply a solution to this for the start of the beginning of the week/month and maybe hour too.

Edit: So if a record was created at 18/07/2011 08:55:00 and another created at 18/07/2011 09:05:00, I want the second record to be picked up by the query and not the first. However if the current GETDATE() is 18/07/2011 09:15:00 then it gets tricky.

how about adding AND r.creationTime >= '9am'?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T19:21:42+00:00Added an answer on May 23, 2026 at 7:21 pm

    Are you really need a hoursFromStartOfThisDay variable?
    If your day is static, from 9 to 5, you can use just this static range:

    -- cache current date to avoid multiple calls
    DECLARE @startOfADay INT
    DECLARE @dayLength INT
    DECLARE @currentDate DATETIME
    SET @currentDate = DATEADD(dd, 0, DATEDIFF(dd, 0, GETDATE()))
    SET @startOfADay = 9
    SET @dayLength = 8
    
    SELECT 
       ...
    FROM
       ...
    WHERE ...
    BETWEEN 
          DATEADD(hh, @startOfADay, @currentDate) 
          AND 
          DATEADD(hh, @startOfADay + @dayLength, @currentDate)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

we can use SQL just like this: SELECT * FROM student WITH(NOLOCK); How can
In SQL you can use SELECT * FROM INFORMATION_SCHEMA.TABLES etc to get information about
In SQL server you can use the DATENAME function to get the day of
In SQL Server you can use the IsNull() function to check if a value
Can I use SQL Authentication with User Instances?
I can use the sql server management studio to open a sqlserver 2000 database,
I work for a ISV. Our product can use both SQL Server and Oracle
I am wondering if you can use Linq to SQL using a .mdf file
In SQL Server you can use an XML datatype and map it to relational
You can use the Filter property of a BindingSource to do SQL like filtering.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.