?
Solved

datetime add hours and minutes

Posted on 2014-08-18
5
Medium Priority
?
151 Views
Last Modified: 2014-08-18
Hello,
I have a string like "10:10" in sql 2012. I want to update datetime column like 2014-08-14 22:02:06.353.
So it will be 2014-08-14 10:10:06.353.
How is best to do that?
0
Comment
Question by:johnson1
  • 2
  • 2
5 Comments
 
LVL 70

Accepted Solution

by:
Scott Pletcher earned 2000 total points
ID: 40268798
DATEADD(MINUTE, RIGHT(string, 2) - DATEPART(MINUTE, datetime_column),
DATEADD(HOUR, LEFT(string, 2) - DATEPART(HOUR, datetime_column), datetime_column))
0
 
LVL 35

Expert Comment

by:David Todd
ID: 40268807
Hi Scott,

I know that in .Net a datetime + a duration => new datetime. Now that SQL has time types, can it do something like that without the messy and slow string conversion above?

Just asking
  David
0
 
LVL 70

Expert Comment

by:Scott Pletcher
ID: 40268898
Not that I see.  I only do two string to int conversions, to extract hours and minutes from the original string input.  What else would you propose?
0
 

Author Closing Comment

by:johnson1
ID: 40269117
Thank you.
0
 
LVL 35

Expert Comment

by:David Todd
ID: 40269324
Hi Scott,

I was wondering if datetime + duration = NewDatetime.

Regards
  David
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
SQL Database Recovery Software repairs the MDF & NDF Files, corrupted due to hardware related issues or software related errors. Provides preview of recovered database objects and allows saving in either MSSQL, CSV, HTML or XLS format. Ensures recov…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.

609 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