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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:10:04+00:00 2026-06-10T22:10:04+00:00

I have been trying this for a while and so far research has not

  • 0

I have been trying this for a while and so far research has not gotten me far other than I need to use something called DATEPART (I have no idea how to use this). My SQL Server is not the greatest.

I have declare @DueDate datetime and through a cursor @DueDate will always been the current row’s DueDate (datetime) column. This so far works perfectly without issue.

Now what I am trying to do is get the hour out of @DueDate, check to see if it is 0, and if the hour is 0, set the @DueDate hour to midnight and then update the rows DueDate column with this @DueDate variable.

As stated above I have the cursor and variables all working, I just don’t know how to get the hour from @DueDate, check what that hour value is, and update the @DueDate variable so its hour is now midnight. I know how the update the table, that is the easy part.

Thanks in advance!

  • 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-06-10T22:10:05+00:00Added an answer on June 10, 2026 at 10:10 pm

    I think this does exactly what you want without using the cursor.

    UPDATE [MyTable]
    SET DueDate = DATEADD(dd, 1, DueDate) -- add one day (set to midnight)
    WHERE DATEPART(hh, DueDate) = 0 -- do this for dates where hour is zero (midnight)
    

    Note that you should avoid using cursors where possible. SQL development requires a different way of thinking. Don’t think about iterations, think atomic. You can do most things in a single statement (one statement can be very long if complicated enough).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been trying this for a while but thus far haven't had any
I've been trying for a whlie on this, and have so far been failing
I have been trying to figure this out for quite a while, but what
I have been trying to solve this problem for a while, but couldn't with
So I have been trying to figure this out for a while, but nothing
I have been trying to find some resource on this topic for a while
Been trying to find this online for a while now. I have a SDL_Surface
I have this problem I've been trying to tackle for a while. I have
I have been working on this problem for a while now. I am trying
I have been trying to figure this out for a while now and even

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.