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 6098939
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T13:12:56+00:00 2026-05-23T13:12:56+00:00

I have a console app that will choose records based on if the user

  • 0

I have a console app that will choose records based on if the user has chosen to be notified daily at a specific hour of the day as well as all records where the user has chosen hourly.
The job will run every 15 minutes.
How do I find a threshold of time between 5 minutes before and 5 minutes after the top of the hour?

This is my code

Declare @Now datetime
Declare @NowHour int
Declare @NowMinute int
Declare @NewNow nvarchar(50)

Set @Now = {fn Now()}
Set @NowHour = (SELECT DATENAME(hh, @Now))
Set @NowMinute = (SELECT DATENAME(mi, @Now))
Set @NewNow = Cast(Cast(@NowHour As nvarchar(2)) + ':' + Cast(@NowMinute As nvarchar(2)) as Time)
Select @Now, @NowHour, @NowMinute, @NewNow

Select *  From vw_consumerAlerts 
Where  casexid not in
(Select casexid from alerthistory)  
And Name = 'Always' 
Or ([Hour] Between DateAdd(minute, -5, @NewNow) And DateAdd(minute, -5, @NewNow))

This is the error I’m getting

The data types time and datetime are incompatible in the greater than or equal to operator.

I got it, I had [Hour] and @NewNow swapped, now I get the correct results with:

    (@NewNow Between DateAdd(minute, -5, [Hour]) And DateAdd(minute, 5, [Hour]))
  • 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-23T13:12:57+00:00Added an answer on May 23, 2026 at 1:12 pm

    Assuming you have defined @TheHour as being the hour in question with 00 minutes/seconds:

    WHERE mydatecol BETWEEN DATEADD(minute, -5, @TheHour) AND DATEADD(minute, 5, @TheHour)
    

    UPDATE

    See this:

    select 1
    where cast('1/1/2010 1:04pm' as time) 
        between cast('1/1/2010 12:55pm' AS time) 
        and cast ('1/1/2010 1:05pm' as time)
    

    time and datetime are different, so you need to cast your datetime to time as I’ve done in the crude example here.

    So in your case:

    Select *  From vw_consumerAlerts 
    Where  casexid not in
        (Select casexid from alerthistory)  
    And Name = 'Always' 
    Or ([Hour] Between cast(DateAdd(minute, -5, @NewNow) as time)
        And cast(DateAdd(minute, -5, @NewNow) as time))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have console app A that references another console app B. B app has
I have a console app that I'm porting to WPF. The application has 3
I have a console app that will be running through a scheduled task and
I have a simple console app that clients will install on their server which
I have a console app that needs to display the state of items, but
I have one console app that is doing some lengthy syncing to an ftp
I have a console app that performs a lengthy process. I am printing out
I have a console app that's geared to be automatically ran as a Scheduled
I have a C# console app App1 that reads a row of data from
Help me, Stackoverflow! I have a simple .NET 3.5 console app that reads some

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.