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

Time conversion

47
HI::
I have an Access Database that automatically collects data from an industrial proccess, each minute I have a new record, then I can count the records and have the amount of time the proccess was on or off, dividing by 60 I can have the Hours; so far fine , now I'd like to convert the resulting digital time into time with format like hh:mm, any ideas how to do it ?

Tks in advance for your help

Raymundo Walle
Feb 22 '10 #1

✓ answered by NeoPa

To convert decimal minutes to a time-format value simply divide by 24 * 60.

Date/Times are stored as whole days and fractions of them, thus 5.5 would represent 5 1/2 days. Divide that by 24 to get 5.5 hours, then again by 60 to get 5.5 minutes.

To prove the value, simply format your result to see what turns up.
Expand|Select|Wrap|Line Numbers
  1. dblValue = 5.5
  2.  
  3. dblValue = dblValue / (24 * 60)  'x / 1440
  4.  
  5. Debug.Print Format(dblValue, "HH:nn:ss")

9 1407
Delerna
1,134 Expert 1GB
unless I am misreading your question, you already asked this here
Feb 22 '10 #2
Delerna
1,134 Expert 1GB
On second read I think I understand now.
Do you mean you have a decimal value representing a time

ie
5.75 minutes as a decimal value which is 5:45 minutes as a time value

That will be a mathematics exercise
Feb 22 '10 #3
rwalle
47
yes Delerna::
I have the decimal value 5.5 and need to have 5:30 Hrs

R Walle
Feb 22 '10 #4
TheSmileyCoder
2,322 Expert Mod 2GB
Expand|Select|Wrap|Line Numbers
  1. Public Function fncTimeFormat(db_input As Double) As String
  2.     'Number of hours
  3.     Dim intHours As Integer
  4.     intHours = Fix(db_input)
  5.  
  6.     'Number of mins
  7.     Dim intMin As Integer
  8.     intMin = (db_input - intHours) * 60
  9.  
  10.     'Output
  11.     fncTimeFormat = Format(intHours, "00") & ":" & Format(intMin, "00")
  12. End Function
There may be other smarter ways of doing it. This is just my 5 cents.


The value can ofcourse be converted to time units by using:
Expand|Select|Wrap|Line Numbers
  1. cdate(fncTimeFormat(5.5))
which would give the result:
05:30:00
Feb 22 '10 #5
NeoPa
32,556 Expert Mod 16PB
To convert decimal minutes to a time-format value simply divide by 24 * 60.

Date/Times are stored as whole days and fractions of them, thus 5.5 would represent 5 1/2 days. Divide that by 24 to get 5.5 hours, then again by 60 to get 5.5 minutes.

To prove the value, simply format your result to see what turns up.
Expand|Select|Wrap|Line Numbers
  1. dblValue = 5.5
  2.  
  3. dblValue = dblValue / (24 * 60)  'x / 1440
  4.  
  5. Debug.Print Format(dblValue, "HH:nn:ss")
Feb 22 '10 #6
Delerna
1,134 Expert 1GB
Interesting Neopa and TheSmileyOne
Heres the approach I normally take within a query

Expand|Select|Wrap|Line Numbers
  1. cstr(  cint(DecVal)  )  &  ':'  &  cstr(     60 * (  DecVal - cint(DecVal)  )     )
which is similat to TSO's first example


I might need to change that....if I can remember yours ... next time :)
Feb 23 '10 #7
NeoPa
32,556 Expert Mod 16PB
I can see where you're coming from, but you should remember the result is supposed to be in numerical format. Converting the type of data for display purposes should only ever be done at the last stage, when interfacing with the user (display on screen etc). Otherwise you are working with foreign principles which need to be converted (for you automatically in most cases but nevertheless extra work). Sometimes such conversions allow unexpected issues into your calculations.

I'm probably overstating the isuue here, but I'd strongly suggest to any of you guys who are serious about your design to understand and work with the different formats data is stored in and worked with.
Feb 23 '10 #8
rwalle
47
Thanks all for your reply, I took Neopa approach since looks simplest way to do it, also thanks for the info about how the Time/ date are handled by Access it helps understand date time calculations

Raymundo Walle
Feb 23 '10 #9
NeoPa
32,556 Expert Mod 16PB
You're welcome Raymundo :)

Welcome to Bytes!
Feb 24 '10 #10

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

Similar topics

4
by: dan glenn | last post by:
Say, I want to set a cookie and have it expire an hour after it's set. It's looking like this is only possible for browsers which are in the same time zone as my server?? In other words, if I...
2
by: learning_C++ | last post by:
I programmed this code with a function "get_current_time" in the begining. When I compiled with the command g++ -Wall -g xxx.xpp -o xxx there are so many errors. please help me and thanks, ...
1
by: heirou | last post by:
I'm a novice in this subject....I've made a database that requires a time conversion. For example, if local time is 1200, determine the time in Korea. I use two fields: a date field, and a time...
6
by: DCSudolcan | last post by:
I know that a program can create and properly initialize an array of pointers to functions at build time, but can something like the following be done at build time? void foo(void); unsigned...
5
by: Paulers | last post by:
Hello, I'm working on an app that requires the functionality to convert the time in Austrailia to the time in New York (EST). I am wondering, what is the bestway to approach this in vb.net? Is...
3
by: Jason S | last post by:
is there any way to use templates to bind integer/floating point constants to a template for compile-time use? e.g. template <double conversion> class meters { const factor = conversion;
3
by: moni | last post by:
Hi, I wanted to convert a time value in the form of time_t into a readable form in C# or vice versa, in order to be able to subtract two time values and give the result in msecs. eg. I...
3
by: Evan Klitzke | last post by:
Although it is not present in ANSI C, the GNU version of stftime supports the conversion character %z, which is a time offset from GMT. The four digit time offset is required in RFC 2822...
5
by: fimarn | last post by:
I am trying to get rid of compile time error that I am getting only in RHEL5 (not in RHEL4) apparently due to the changes in the stl_list.h file. The error that I am getting is coming from the...
5
by: Grey Alien | last post by:
I need to convert timestamps that are given as the number of seconds that have elapsed since midnight UTC of January 1, 1970, (not counting leap seconds). It seems all of the std C functions...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.