Solved

subtract two datetime fields (start and finish) with the result being datetime

Posted on 2013-05-21
3
418 Views
Last Modified: 2013-05-22
what datatype hours:minutes is the subtraction between two datetime fields

do not just want to calculate difference

because I want to store this value in a field
0
Comment
Question by:rgb192
3 Comments
 

Accepted Solution

by:
kavi112 earned 250 total points
ID: 39186633
Use DATEDIFF to find datetime differences. and use DATEPART to control the format of the result.
ex:
SELECT DATEDIFF (datepart, '2010-01-22 15:29:55.090', '2010-01-22 15:30:09.153')
Substitute "datepart" based on DATEDIFF on MSDN
0
 
LVL 48

Assisted Solution

by:PortletPaul
PortletPaul earned 250 total points
ID: 39186662
datediff is the function for the wanted subtraction, but you must decide what time units you will store, e.g.

set somefield = datediff(second,start_date,end_date)

set somefield = datediff(minute,start_date,end_date)

(I generally see seconds used in such situations.)

You might consider using a 'calculated column'  if this suits the purpose.
0
 

Author Closing Comment

by:rgb192
ID: 39186757
thanks
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Suggested Solutions

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

929 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

8 Experts available now in Live!

Get 1:1 Help Now