473,486 Members | 2,424 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Convert seconds to days, hours, minutes and seconds.

Hello -

I have about ten integer values that each need to be converted to days,
hours, minutes and seconds. I can't seem to find a formula for same that
works. These integer values come from a Sql Server database that SUMS up the
seconds. The only way SUM will work in SS is with an integer value,
therefore, I could not use datetime in Sql Server.)

I need to ultimately put the converted values into ten datetimepicker
controls.

Does anyone have code for doing this? Any help will be appreciated!
--
Sheldon
Jul 5 '08 #1
5 12783
On Jul 5, 3:37*pm, Sheldon <Shel...@discussions.microsoft.comwrote:
Hello -

I have about ten integer values that each need to be converted to days,
hours, minutes and seconds. *I can't seem to find a formula for same that
works. *These integer values come from a Sql Server database that SUMS up the
seconds. *The only way SUM will work in SS is with an integer value,
therefore, I could not use datetime in Sql Server.)

I need to ultimately put the converted values into ten datetimepicker
controls.

Does anyone have code for doing this? *Any help will be appreciated!
--
Sheldon
Sounds like a good job for some simple looping and straight division.
You should be able to figure it out once you start playing with some
code.

Thanks,

Seth Rowe [MVP]
http://sethrowe.blogspot.com/
Jul 5 '08 #2

"Sheldon" <Sh*****@discussions.microsoft.comkirjoitti viestissä
news:5B**********************************@microsof t.com...
Hello -

I have about ten integer values that each need to be converted to days,
hours, minutes and seconds. I can't seem to find a formula for same that
works. These integer values come from a Sql Server database that SUMS up
the
seconds. The only way SUM will work in SS is with an integer value,
therefore, I could not use datetime in Sql Server.)

I need to ultimately put the converted values into ten datetimepicker
controls.

Does anyone have code for doing this? Any help will be appreciated!
There are many ways to do this, but can you find this example useful:

Dim Seconds As Integer = 500
Dim Example1 As New TimeSpan(0, 0, Seconds)
Dim Example2 As DateTime
Example2 = Example2.AddSeconds(Seconds)

MsgBox(Seconds & " seconds is " & Example1.TotalHours & " hours")
MsgBox(Seconds & " seconds is " & Example2.Minute & " minutes and "
_
& Example2.Second & " seconds")

-Teemu

Jul 5 '08 #3

"Sheldon" <Sh*****@discussions.microsoft.comwrote in message
news:5B**********************************@microsof t.com...
Hello -

I have about ten integer values that each need to be converted to days,
hours, minutes and seconds. I can't seem to find a formula for same that
works. These integer values come from a Sql Server database that SUMS up
the
seconds. The only way SUM will work in SS is with an integer value,
therefore, I could not use datetime in Sql Server.)

I need to ultimately put the converted values into ten datetimepicker
controls.

Does anyone have code for doing this? Any help will be appreciated!
--
Sheldon

'The number of seconds in a day is (24 * 60 * 60 )
'Assuming TotalSeconds is your variable
'use integer division
Dim Daycount as Integer = TotalSeconds \ (24 * 60 * 60)
Dim SecondsRemaining as Integer = TotalSeconds - (DayCount * (24 * 60 *
60) )
Dim HourCount as Integer = SecondsRemaining \ (60 * 60)
SecondsRemaining = SecondsRemaining Mod (60 * 60)
Dim MinutesCount as Integer = SecondsRemaining \ 60
Dim SecondsCount as Integer = SecondsRemaining Mod 60


Jul 6 '08 #4
Sheldon wrote:
Hello -

I have about ten integer values that each need to be converted to days,
hours, minutes and seconds. I can't seem to find a formula for same that
works. These integer values come from a Sql Server database that SUMS up the
seconds. The only way SUM will work in SS is with an integer value,
therefore, I could not use datetime in Sql Server.)

I need to ultimately put the converted values into ten datetimepicker
controls.

Does anyone have code for doing this? Any help will be appreciated!
The most straight forward method is to simply turn the seconds into a
TimeSpan value:

t AS TimeSpan = TimeSpan.FromSeconds(seconds)

If you need a DateTime value, you have to pick a date that you start
counting from (i.e. the date that a zero seconds value would represent).
Then you just add the seconds to that.

d As DateTime = new DateTime(2008,1,1).AddSeconds(seconds)

--
Göran Andersson
_____
http://www.guffa.com
Jul 6 '08 #5
"Sheldon" <Sh*****@discussions.microsoft.comschrieb
Hello -

I have about ten integer values that each need to be converted to
days, hours, minutes and seconds. I can't seem to find a formula
for same that works. These integer values come from a Sql Server
database that SUMS up the seconds. The only way SUM will work in SS
is with an integer value, therefore, I could not use datetime in Sql
Server.)

I need to ultimately put the converted values into ten
datetimepicker controls.

Does anyone have code for doing this? Any help will be appreciated!

Use the TimeSpan structure, for example

Dim ts = TimeSpan.FromSeconds(1234)

Then you can access it's members, ts.days, ts.hours etc.
Armin
Jul 6 '08 #6

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

Similar topics

1
12315
by: NotGiven | last post by:
Below is a good elapsed time function I found. However, I'd like to return total seconds instead of broken down into days, hours, minutes & seconds. In other words, I want "125" instead of "2...
2
80893
by: Rudi Groenewald | last post by:
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...
2
1718
by: tdi1686 | last post by:
I want to make a table that lists the Seconds / Hours / Days since the user last visited my site, just like the myPHPnuke systems have, but I dont know the best way to go about it. At the moment...
2
6740
by: 00_CP_D12 | last post by:
Is there an easy way in ASP.NET to convert seconds to Hours: Minutes: Seconds? For example, 65 seconds will return 0 hr, 1 min, 5 secs. Thanks...
6
3085
by: Able | last post by:
Dear friends I need to format seconds as hh:mm:ss. I see a lot of coding transforming seconds to hh:mm:ss. Somebody know a short way? Regards Able
29
2604
by: Jan | last post by:
Hi: I have an Access database that's been running (in one form or another) for a couple of different clients for a few years. Now a new client has requested that it be implemented with a SQL...
6
30584
by: Carl J. Van Arsdall | last post by:
Basically I used the datetime module and timedelta objects to calculate a difference between two times. Now I'm trying to figure out how I make that time delta a string HH:MM:SS to show elapsed...
7
14898
by: WorldIsEnding | last post by:
Hey, Im having trouble with converting a Numeric value (such as a single digit number like 1 or 5) into a time format. I need to convert a number entered into a variable into Hours on the...
3
6302
by: =?Utf-8?B?U2hlbGRvbg==?= | last post by:
Hello - I have various times formatted like 00:00:00, so for example, 01:32:05 would be one thirty-two with five milliseconds. I need to convert this into seconds (an integer). First of...
0
7100
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7126
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
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4865
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
4559
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
3070
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
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
598
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.