473,396 Members | 1,966 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,396 software developers and data experts.

Conversion of seconds to hours and minutes

In another post requiring conversion, I could see how you helped the person, but my field is a bit different and I do not code well. My field is on a report and reads: =Sum([Seconds]). It is comprised of the sum of the seconds that I need to convert. What needs to be written to turn it into hours, minutes and seconds?

Thank you,

Rio
Sep 6 '06 #1
20 19929
PEB
1,418 Expert 1GB
I have a proposal but it isn't perfect! You don't need to write functions it's already done!


= format(Sum([Seconds])**0.000694444444/60,"hh:mm:ss")
Sep 6 '06 #2
PEB
1,418 Expert 1GB
Opa!

= format(Sum([Seconds])*0.000694444444/60,"hh:mm:ss")
You have to pay attention with the decimal! If you use decimal virgul instaed point you may have problems!
Sep 6 '06 #3
Opa!

= format(Sum([Seconds])*0.000694444444/60,"hh:mm:ss")
You have to pay attention with the decimal! If you use decimal virgul instaed point you may have problems!
I copied and pasted the string and get an error that says:
"The expression you entered contains invalid syntax. You may have entered a comma without a preceeding value or identifier."

Rio
Sep 6 '06 #4
PEB
1,418 Expert 1GB
Change the point with virgula in this expression
or
better type

=format(Sum([Seconds])*val("0.000694444444")/60,"hh:mm:ss")

This have to work!
Sep 6 '06 #5
Change the point with virgula in this expression
or
better type

=format(Sum([Seconds])*val("0.000694444444")/60,"hh:mm:ss")

This have to work!

Danke! THAT one works! I owe you!

Rio
Sep 6 '06 #6
Well, I am back because, after fiddling with it, I realized that this formula

=Format(Sum([Seconds])*Val("0.000694444444")/60,"hh:nn:ss")

will not convert and get me to days, as in dd:hh:mm:ss. What, pray tell, do I need to add?

Rio
Sep 7 '06 #7
MMcCarthy
14,534 Expert Mod 8TB
Your typed "hh:nn:ss" instead of "hh:mm:ss", may just be a typo.

Back to your question have you tried changing "hh:mm:ss" to "dd:hh:mm:ss".


Well, I am back because, after fiddling with it, I realized that this formula

=Format(Sum([Seconds])*Val("0.000694444444")/60,"hh:nn:ss")

will not convert and get me to days, as in dd:hh:mm:ss. What, pray tell, do I need to add?


Rio
Sep 7 '06 #8
PEB
1,418 Expert 1GB
Try "dd/mm/yyyy hh:mm:ss"

or "yyyy/mm/dd hh:mm:ss"

:)
Sep 8 '06 #9
"dd/mm/yyyy hh:mm:ss" returns 31/12/1899 31:22:05:37

and

"yyyy/mm/dd hh:mm:ss" returns 1899/12/31 22:05:37

What I need the return to be is 1:22:05:37 which represents 1 day, 22 hours, 5 mins, 37 seconds. My original total seconds is 165937.

If I use "dd:hh:mm:ss", it returns 31:22:05:37, and I know this problem exists because the clock turns over at 12:00 PM, but I really do not know how to fix it. Somebody help me!

Rio
Sep 8 '06 #10
PEB
1,418 Expert 1GB
So a function that can gives you the days is Datediff()

datediff("d",0,165937/60*Val("0.000694444444"))

and format gives you the other difference

You can do the following:
=datediff("d",0,Seconds/60*Val("0.000694444444"))+Format(165937/60*Val("0.000694444444"),"hh:mm:ss")

:)
Sep 8 '06 #11
MMcCarthy
14,534 Expert Mod 8TB
Try using a function something like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function TimeInterval(value As Long) As String
  3. ' pass in a value in seconds
  4. Dim secVal As Integer
  5. Dim minVal As Integer
  6. Dim hourVal As Integer
  7. Dim dayVal As Integer
  8.  
  9.     dayVal = value / 86400
  10.     hourVal = (value - (86400 * dayVal)) / 3600
  11.     minVal = (value - ((3600 * hourVal) + (86400 * dayVal))) / 60
  12.     secVal = (value - ((60 * minVal) + (3600 * hourVal) + (86400 * dayVal)))
  13.  
  14.     TimeInterval = dayVal & ":" & hourVal & ":" & minVal & ":" & secVal
  15. End Function
  16.  
  17.  


"dd/mm/yyyy hh:mm:ss" returns 31/12/1899 31:22:05:37

and

"yyyy/mm/dd hh:mm:ss" returns 1899/12/31 22:05:37

What I need the return to be is 1:22:05:37 which represents 1 day, 22 hours, 5 mins, 37 seconds. My original total seconds is 165937.

If I use "dd:hh:mm:ss", it returns 31:22:05:37, and I know this problem exists because the clock turns over at 12:00 PM, but I really do not know how to fix it. Somebody help me!

Rio
Sep 8 '06 #12
Try using a function something like this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. Function TimeInterval(value As Long) As String
  3. ' pass in a value in seconds
  4. Dim secVal As Integer
  5. Dim minVal As Integer
  6. Dim hourVal As Integer
  7. Dim dayVal As Integer
  8.  
  9.     dayVal = value / 86400
  10.     hourVal = (value - (86400 * dayVal)) / 3600
  11.     minVal = (value - ((3600 * hourVal) + (86400 * dayVal))) / 60
  12.     secVal = (value - ((60 * minVal) + (3600 * hourVal) + (86400 * dayVal)))
  13.  
  14.     TimeInterval = dayVal & ":" & hourVal & ":" & minVal & ":" & secVal
  15. End Function
  16.  
  17.  

Do I need to put a field on my report to reflect this function?

Rio
Sep 11 '06 #13
MMcCarthy
14,534 Expert Mod 8TB
=TimeInterval([Seconds])



Do I need to put a field on my report to reflect this function?

Rio
Sep 11 '06 #14
=TimeInterval([Seconds])
Now, I'm getting a compile error. May I send you a copy of this database? It is very small, containing only one table, a query and a report.

Rio
Sep 11 '06 #15
MMcCarthy
14,534 Expert Mod 8TB
Make control source of your field equal to:

[font=Arial][size=2]=TimeInterval(Sum([howlong]))[/size][/font]
[font=Arial][size=2][/size][/font]
[font=Arial][size=2]And replace the Timer Inverval function with the following one:[/size][/font]
[font=Arial][size=2][/size][/font]
Expand|Select|Wrap|Line Numbers
  1.  
  2. [font=Arial][size=2]Function TimeInterval(value As Long) As String
  3. ' pass in a value in seconds
  4. Dim secVal As Integer
  5. Dim minVal As Integer
  6. Dim hourVal As Integer
  7. Dim dayVal As Integer
  8. Dim days As Long
  9. Dim hours As Long
  10. Dim mins As Long[/size][/font]
  11. [font=Arial][size=2][/size][/font] 
  12. [font=Arial][size=2]    days = 86400
  13.     hours = 3600
  14.     mins = 60
  15.  
  16.     dayVal = Fix(value / days)
  17.     value = value - (dayVal * days)
  18.     hourVal = Fix(value / hours)
  19.     value = value - (hourVal * hours)
  20.     minVal = Fix(value / mins)
  21.     value = value - (minVal * mins)
  22.     secVal = value
  23.  
  24.     TimeInterval = dayVal & ":" & hourVal & ":" & minVal & ":" & secVal
  25.  
  26. End Function[/size][/font]
  27.  
Now, I'm getting a compile error. May I send you a copy of this database? It is very small, containing only one table, a query and a report.

Rio
Sep 12 '06 #16
MMcCarthy
14,534 Expert Mod 8TB
Sorry about all the formatting in previous post. It came in with a copy and paste.

Make control source of your field equal to:

TimeInterval(Sum([howlong]))

And replace the Timer Inverval function with the following one:


Expand|Select|Wrap|Line Numbers
  1.  
  2. Function TimeInterval(value As Long) As String
  3. ' pass in a value in seconds
  4. Dim secVal As Integer
  5. Dim minVal As Integer
  6. Dim hourVal As Integer
  7. Dim dayVal As Integer
  8. Dim days As Long
  9. Dim hours As Long
  10. Dim mins As Long
  11.  
  12.     days = 86400
  13.     hours = 3600
  14.     mins = 60
  15.  
  16.     dayVal = Fix(value / days)
  17.     value = value - (dayVal * days)
  18.     hourVal = Fix(value / hours)
  19.     value = value - (hourVal * hours)
  20.     minVal = Fix(value / mins)
  21.     value = value - (minVal * mins)
  22.     secVal = value
  23.  
  24.     TimeInterval = dayVal & ":" & hourVal & ":" & minVal & ":" & secVal
  25.  
  26. End Function
  27.  
  28.  
Sep 12 '06 #17
This is fabulous! The database is just what I needed and I hope that I will be able to show my appreciation for all of the help I was given by helping someone else. I may not be an Access whiz, but there are a number of other programs on which I am SMOKIN'!

Thanks so much once again!

Rio
Sep 13 '06 #18
I tried to use this module and it works great except the minutes and seconds do not come out right. Do you have same problem? Example I have a second value as 15037 and it comes out as 4h10m37s but it should be 4h18m9s, no?
Nov 30 '06 #19
I think it's me that calculate wrongly. Sorry for confusion.
Nov 30 '06 #20
I know this thread has been dead for a long time, I just wanted to say thanks!You helped resolve an issue on a report I was developing and was beating my head against the keyboard over.
Nov 3 '07 #21

Sign in to post your reply or Sign up for a free account.

Similar topics

2
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...
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...
2
by: J M | last post by:
I rebooted a network device just few minutes ago and getting device-up-time value 3191. How do I convert a time elapsed in days hours minutes and seconds for above value? Example: This device...
2
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...
1
by: markdp | last post by:
I'm trying to write a program that takes a user inputted number of seconds and converts it into hours, minutes and seconds. So for instance, the program prompts the user for seconds, lets say 1000...
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...
12
by: remya1000 | last post by:
how can i select time (hours,minutes,second) in updown arrow buttons in VB.NET. as we have current time displayed in date and time properties in our system. in date and time properties, while...
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...
5
by: =?Utf-8?B?U2hlbGRvbg==?= | last post by:
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...
6
by: Candy6 | last post by:
#include <iostream> #include <string> using namespace std; int main() { int seconds; int minutes; int hours;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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
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
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...
0
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...
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,...

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.