473,806 Members | 2,565 Online
Bytes | Software Development & Data Engineering Community
+ 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 12889
On Jul 5, 3:37*pm, Sheldon <Shel...@discus sions.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*****@discus sions.microsoft .comkirjoitti viestissä
news:5B******** *************** ***********@mic rosoft.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.AddSec onds(Seconds)

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

-Teemu

Jul 5 '08 #3

"Sheldon" <Sh*****@discus sions.microsoft .comwrote in message
news:5B******** *************** ***********@mic rosoft.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 SecondsRemainin g as Integer = TotalSeconds - (DayCount * (24 * 60 *
60) )
Dim HourCount as Integer = SecondsRemainin g \ (60 * 60)
SecondsRemainin g = SecondsRemainin g Mod (60 * 60)
Dim MinutesCount as Integer = SecondsRemainin g \ 60
Dim SecondsCount as Integer = SecondsRemainin g 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.FromSe conds(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*****@discus sions.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.FromSe conds(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
12346
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 minutes 5 seconds". Any ideas? Thanks very much! function calcElapsedTime($time) { // calculate elapsed time (in seconds!) $diff = time()-$time;
2
81024
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 called: "Diff" Thanks alot
2
1741
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 when the user calls the page the database is updated with the current date/time for that user. Should I do this in the VB code in the page or write a SQL statement to do this?
2
6754
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
3108
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
2649
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 server back-end. I'm doing my best to learn about SQL server, and I plan to leave the front-end more or less as-is, just linking to the SQL server back end, but here's a basic question: The db has a front-end linked to two back-ends. One of the...
6
30609
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 time. I've spent tons of time looking at the module's documentation but I'm not seeing how those methods will help me. Can anyone help me with this? Here's what I'm trying to do, assum that resultsDict is a dictionary of objects that have...
7
14973
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 first form, then from Hours into Seconds when a second form is loaded. Anyone got any ideas? If you need more info, let me know and ill post a code snippet or something.
3
6359
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 all, I have been unable to use the mid() function like I did in vb 6.
0
9719
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9597
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10620
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10369
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10372
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7650
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6877
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
4329
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3008
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.