473,426 Members | 1,777 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,426 software developers and data experts.

Convert Seconds to hours:minutes:seconds

Hi all.

If I've got a query which has a field with seconds in it... how will I use
the Convert function to get my field converted to the format: HH:MM:SS ?

The field with the seconds in is called: "Diff"
Thanks alot

Rudi

Jul 23 '05 #1
2 80883

I am not sure where this is correct way of finding

Try this

declare @sec int
set @sec=7612
select
convert(varchar(5),@sec/3600)+':'+convert(varchar(5),@sec%3600/60)+':'+convert(varchar(5),(@sec%60))

Madhivanan

Jul 23 '05 #2
On Wed, 9 Mar 2005 11:06:07 +0200, Rudi Groenewald wrote:
If I've got a query which has a field with seconds in it... how will I use
the Convert function to get my field converted to the format: HH:MM:SS ?

The field with the seconds in is called: "Diff"


Hi Rudi,

You can use the suggestion Madhivanan proposes (that one will display
total hours, even if it's more than 24, but it will trim seconds and
minutes, leading to output like 11:5:3 instead of 11:05:03).

An other simple way (that will only work correct if the number of hours
is less than 24) is to use datetime logic:

SELECT CONVERT(char(8), DATEADD(second, Diff, '0:00:00'), 108)

If you need the ability to handle times > 24 hours, AND you want to
display 11:05:03 instead of 11:5:3, then you need to use a slightly more
complicated version of Madhivanan's suggestion:

SELECT CONVERT(varchar(6), Diff/3600)
+ ':' + RIGHT('0' + CONVERT(varchar(2), (Diff % 3600) / 60), 2)
+ ':' + RIGHT('0' + CONVERT(varchar(2), Diff % 60), 2)

Best, Hugo
--

(Remove _NO_ and _SPAM_ to get my e-mail address)
Jul 23 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Deepa | last post by:
I need a routine to convert milliseconds to a traditional dd:hh:mm:ss or four separate variables that I can display. I am not wanting to display a date but rather the interval between two...
3
by: fred14214 | last post by:
I need to be able to enter an elapsed time into a text field. This time then needs to be converted into seconds and stored in a field in some table. The user will enter a time (format is...
7
by: Stu | last post by:
Is there a simple function call within "C" that I can use to convert number of seconds (keep in mind this may be a type longlong and has to work on UNIX and NT) into Days, months, Hours, Minutes...
7
by: tshad | last post by:
Is there a quick function in vb out there that will convert seconds to minutes and seconds? Thanks, Tom
1
by: Lorisabel | last post by:
I would like to ask for some help with this assignment as i don't know how to start it. Write a C++ program that prompts the user to input the elapsed time for an event in seconds. The program...
3
by: Bert Murphy | last post by:
Im trying to write code that would have seconds for the input,convert the seconds to the hours:minutes:seconds,accumulate the hours:minutes:seconds to a maximum of 999Hours:59Minutes:59Seconds as...
1
by: krizzie khonnie | last post by:
Hi, Can anyone help? How can I show the the correct format if I used this code :B_ros_poe_entry.last_saved_date := SYSDATE;. I'm expecting that this should generate MM-DD-YYYY HH:MM:SS but...
6
by: Candy6 | last post by:
#include <iostream> #include <string> using namespace std; int main() { int seconds; int minutes; int hours;
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.