Solved

SQL server add hours and minutes to datetime

Posted on 2014-03-11
3
906 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 250 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 250 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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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.

691 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