Solved

SQL server add hours and minutes to datetime

Posted on 2014-03-11
3
691 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
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you!
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

772 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now