Solved

Converting to Hrs and mins

Posted on 2011-03-22
3
201 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

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
placing a checked in the checklistbox based on the value in database table. 3 40
Validating Date Part2 2 25
Json and ajax 1 18
Hide and Unhide Table 6 24
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

713 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