Working with Elapsed Time

Started by sukishan, Sep 04, 2009, 04:50 PM

Previous topic - Next topic

sukishan

Working with Elapsed Time
No matter how much you'd like VBA date/time values to be able to track elapsed time, they're not built that way. As designed, VBA date/time values store a particular point in time, not a span of time, and there's no way to store more than 24 hours in a given date/time variable. If you want to work with elapsed times, you'll generally have to do some conversion work, storing the elapsed times in a numeric datatype and converting them back to a formatted output for display. Other elapsed time issues simply return an integer value indicating the number of elapsed units (year, days, months) between two dates.

This section covers several standard issues when dealing with elapsed times, including these topics:

Finding the number of workdays between two dates


Returning a person's age, in years, given the birth date


Formatting elapsed time using a format specification string


Formatting cumulative times
Finding Workdays between Two Dates

Many applications require you to calculate the number of days between two dates (and you can simply use DateDiff or subtract the first date value from the second, if that's all you need). In addition, many business applications need to know the number of workdays between two dates, and that's a bit more complex. The function in this section, dhCountWorkdays, uses the code presented previously (see the section "Working with Workdays") to skip holidays and weekends
A good beginning makes a good ending