Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Time

Status
Not open for further replies.

pleg12345

IS-IT--Management
Dec 21, 2003
48
EU
Does anyone know how to average two periods of time?
 
Add them together and divide by two.





However, I suspect there is more to your question than that !

How do you have your 'time periods' stored ?
What format do you expect to present the results in ?




G LS
spsinkNOJUNK@yahoo.co.uk
Remove the NOJUNK to use.
 
You can use the DateDiff and DateAdd functions:

' Find the difference between the 2 dates
' This example uses minutes ("n")
x = DateDiff("n", date1, date2)

' Then take the difference / 2 and add that
' to the earlier date
MsgBox DateAdd("n", (x / 2), date1)

Please read the Help file about the DateDiff function for other intervals besides minutes ("n")

Hope this helps,

Don
 
When you say "two periods of time" do you mean data like this~

Sept 6, 1939
Jan 1, 2000

or like this~

2 hours 35 minutes
1 century, four hours, and three seconds

If you have two specific points in time, you can find the midpoint between them using datediff. I agree with the last poster.

If you have two time periods, you will need to write a short VB program. Basically, this VB code should
a) convert value one to a certain timescale
b) convert value two to a certain timescale
c) find the average of the two values
d) convert that quotient to a normal phrase

The timescale should be the smallest time unit. For example, if the values were

two days, four minutes
and
three hours, sixteen minutes, three seconds

then the timescale should be seconds.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top