Solved

Query to get minutes and seconds

Posted on 2009-05-11
1
318 Views
Last Modified: 2013-11-30
Hi All,

I'm trying to write a query which will give me difference between two datetime columns, but the problem is I get answer only in minutes or seconds. I want to have the answer as hh:mm:ss. Below is the query I'm using

For example

Results

X          y       [Total Time] (in mins)
abc     fcd      8

But I want

x          y        [Total Time] (in mm:ss)
abc    fcd        8:24


Thanks
SELECT X,Y,Z, DATEDIFF("n",[Start time], [End time]) as [Total Time]
FROM  [Table  A]

Open in new window

0
Comment
Question by:Samoin
1 Comment
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 250 total points
ID: 24356469
SELECT X,Y,Z, CONVERT(varchar,[End time] -[Start time], 108)  as [Total Time]
FROM  [Table  A]
0

Featured Post

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

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.
The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

786 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