Solved

SQL server add hours and minutes to datetime

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

773 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