Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SQL server add hours and minutes to datetime

Posted on 2014-03-11
3
Medium Priority
?
1,068 Views
Last Modified: 2014-03-13
Hello: I have many records in a SQL Server 2008 database with a datecompleted set to a range of values in the year and day, but the time is 00:00:00.

I need to update these records individually and set the time to 23:58:00 while leaving the year/day as it is.

What's the safe and proper syntax to do that?

Thanks
0
Comment
Question by:KnowledgeWare
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 21

Accepted Solution

by:
Dale Burrell earned 1000 total points
ID: 39922253
Loads of ways, one is:

update MyTable set DateCompleted = dateadd(mi, 58, dateadd(hi, 23, DateCompleted))
0
 
LVL 7

Assisted Solution

by:Kishan Zunjare
Kishan Zunjare earned 1000 total points
ID: 39925574
I believe you need the DATEADD function:

DECLARE @Date DAtetime
SET @Date = DATEADD(hh, 23, '03/13/2014')
SET @Date = DATEADD(mi, 58, @Date)
SELECT @Date
0
 

Author Closing Comment

by:KnowledgeWare
ID: 39926943
Thank you!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
Ready to get certified? Check out some courses that help you prepare for third-party exams.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question