Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2013-05-21
3
Medium Priority
?
425 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
[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
 

Accepted Solution

by:
kavi112 earned 1000 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 49

Assisted Solution

by:PortletPaul
PortletPaul earned 1000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

618 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