Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 427
  • Last Modified:

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

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
rgb192
Asked:
rgb192
2 Solutions
 
kavi112Commented:
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
 
PortletPaulCommented:
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
 
rgb192Author Commented:
thanks
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now