Solved

Converting to Hrs and mins

Posted on 2011-03-22
3
199 Views
Last Modified: 2012-05-11
How can I convert seconds to Hrs and minutes using sql command?

pls help.

ayha
0
Comment
Question by:ayha1999
3 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 125 total points
ID: 35190782
Do you want this to happen on sqlserver or in code ?
declare
	@sec	int

select	@sec = 64597

select	right('0' + rtrim(convert(char(2), @sec / (60 * 60))), 2) + ':' + 
	right('0' + rtrim(convert(char(2), (@sec / 60) % 60)), 2) + ':' + 
	right('0' + rtrim(convert(char(2), @sec % 60)),2)

Open in new window

0
 
LVL 8

Expert Comment

by:Anurag Agarwal
ID: 35190785
try this !!

DECLARE @SecondsToConvert int
SET @SecondsToConvert = 10000  (your seconds)


-- Declare variables
DECLARE @Hours int
DECLARE @Minutes int
DECLARE @Seconds int
DECLARE @Time datetime

-- Set the calculations for hour, minute and second
SET @Hours = @SecondsToConvert/3600
SET @Minutes = (@SecondsToConvert % 3600) / 60
SET @Seconds = @SecondsToConvert % 60

-- Store the datetime information retrieved in the @Time variable
SET @Time = (SELECT
RTRIM(CONVERT(char(8), @Hours) ) + ':' +
CONVERT(char(2), @Minutes) + ':' +
CONVERT(char(2), @Seconds));

-- Display the @Time variable in the format of HH:MM:SS
SELECT CONVERT(varchar(8),CONVERT(datetime,@Time),108)

0
 
LVL 7

Author Closing Comment

by:ayha1999
ID: 35190951
thanks
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

773 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