> Each entry in a data file includes date and time in text format - e.g.
"0601271325" = 2006, January 27th, 1:25 pm. Is there a simple way to
calculate the hours (including decimal parts) between two of these
entries?
You could use the following function to convert your "dates" from their
non-standard format to a normal date format...
Function ConvertDate(DateIn As String) As Date
ConvertDate = DateSerial(Left$(DateIn, 2), Mid$(DateIn, 3, 2), _
Mid$(DateIn, 5, 2)) + CDate(Mid$( _
DateIn, 7, 2) & ":" & Right$(DateIn, 2))
End Function
and then use the DateDiff function on the results. Something like this for
example...
NumberOfSeconds = DateDiff("s", ConvertDate(D1), ConvertDate(D2)
Note that this returns the number of seconds between the two dates. To get
hours and decimals of an hour, you would need to divide the number of
seconds by 3600 (the number of seconds in an hour)....
NumberOfHours = NumberOfSeconds / 3600
One additional note about your strange date format... there is a possibility
that the 2-digit year format could be interpreted differently on different
systems. The "breakpoint" between when a 2-digit year is considered in the
2000 century and when it is considered in the 1900 century is user
configurable and out of your control. If you know all of your dates are
going to be in the 2000 century, you could append "20" onto the beginning of
the Left$(DateIn,2) term in the DateSerial function to force that
interpretation; otherwise, you results might be at the hands of the local
setting on the computer your program is running on (depending on the span of
years your program must be able to handle).
Rick