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

VB6 - hours between dates/times

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?
Jun 16 '06 #1
1 11580
> 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

Jun 16 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Phil Sandler | last post by:
All, I have a table with start and end dates/times in it, and would like to be able to calculate the number of hours represented, accounting for overlapping records. Note that I am looking...
8
by: Monty | last post by:
Let's say you provide an online service from 7:00AM to 6:00PM Eastern Time (daylight time in the summer). Is there way of showing these hours of availability on a web page in the user's local...
5
by: mitchchristensen | last post by:
I have a transaction log that tracks issues from a call center. Each time an issue is assigned to someone else, closed, etc. I get a time stamp. I have these time stamps for the beginning of an...
5
by: Rebecca Smith | last post by:
I'm building log book to keep track of a racers stats during a long ultra marathon race. Things such as time on the bike, time off, H20 intake, electrolytes and the like. When I say long I mean...
10
by: Geoff Jones | last post by:
Hi I'm hoping that somebody can help me with the following question. I have a DataView which contains a column which contains a Time. I would like to create an array which will store the...
1
by: lottaviano | last post by:
My table lists pieces of equipment and the date/time they are taken down for maintenance, and date/time maintenance is complete (put back up to production). Sometimes these dates/times are within...
23
by: tatata9999 | last post by:
Hi, What time zones tend to use 24 hours time format? Googling hasn't been able to answer the question. Thank you.
4
by: jnice814 | last post by:
I have created a frmTimesheet form where auditors will enter their hours for audits that they've worked on. I know how to build a very basic, no-frills database, and what I'm trying to accomplish...
18
by: Dirk Hagemann | last post by:
Hello, From a zone-file of a Microsoft Active Directory integrated DNS server I get the date/time of the dynamic update entries in a format, which is as far as I know the hours since january 1st...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.