Solved

Converting to Hrs and mins

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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
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…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

747 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now