Others

How to Convert Milliseconds to [h]:mm:ss in Access VBA

Bushra ParveenBushra Parveen Nov 3, 2026 869 views

Question details

The user needs to convert a duration stored in milliseconds into an [h]:mm:ss elapsed-time format using Microsoft Access VBA, specifically ensuring that durations over 24 hours are handled correctly.

How to Convert Milliseconds to [h]:mm:ss in Access VBA
Product
Microsoft Access
Device & OS
not provided
Scenario
Writing a VBA script or query where time durations are tracked in milliseconds and must be displayed in a human-readable format of hours, minutes, and seconds.
Observed behavior
A script or expression is needed to correctly calculate the millisecond value into fractions of a day and format it so hours can exceed a standard 24-hour limit without rolling over.
Before you start

Ensure you have your Microsoft Access database open and access to the VBA editor. It is helpful to identify the exact variable, field, or control name that contains your millisecond values before applying the formula.

Solution 1Recommended

Convert and Format Milliseconds Using Division

Use a mathematical formula to transform your millisecond data into days, and then format the result to properly display elapsed hours, minutes, and seconds.

Microsoft Access stores date and time values internally as fractions of a single day. To correctly format milliseconds, you must first convert that value into a daily fraction by dividing it by the total number of milliseconds in a 24-hour period.

1
Locate Your Millisecond Value

Identify the specific field or variable in your Access VBA code that holds the duration in milliseconds.

2
Divide by 86,400,000

In your VBA script or query expression, divide the millisecond value by 86,400,000. This number represents the total milliseconds in one day (24 hours × 60 minutes × 60 seconds × 1000 milliseconds).

3
Apply the Custom Format

Format the resulting decimal value using the string '[h]:mm:ss'. The brackets around the 'h' instruct Access to display elapsed hours, preventing the time from resetting to zero once it surpasses 24 hours.

Convert and Format Milliseconds Using Division
Support for Extended Durations: By utilizing the [h] format, a duration of 25 hours will correctly display as '25:00:00' instead of '01:00:00', making it ideal for tracking long-running tasks.
Free Microsoft Office alternative

Try WPS Office for Your Data and Spreadsheet Needs

While Microsoft Access handles complex relational databases, many data tracking and time conversion tasks are easier to manage in spreadsheets. WPS Office provides a free, lightweight, and highly compatible alternative to Microsoft Office, complete with advanced spreadsheet functions for handling time data effortlessly.

  1. 1. Download and Install WPS Office: Get the free productivity suite from the official WPS website and install it on your device.
  2. 2. Open Your Data in WPS Spreadsheet: Launch WPS Spreadsheet and import your CSV or Excel files containing the time or duration data.
  3. 3. Apply Custom Time Formatting: Select the cells with your time values, right-click and choose 'Format Cells', then apply the '[h]:mm:ss' custom format directly.
Fully compatible with Microsoft Excel (.xlsx) formats and time calculation formulas.Easily format time durations using [h]:mm:ss without the need for complex VBA scripting.Lightweight installation and familiar interface for a seamless migration.A feature-rich, free alternative to costly Microsoft Office subscriptions.
microsoft office alternative - wps office

Frequently Asked Questions

Why use [h] instead of h in the time format?

Using [h] with brackets forces the application to display total elapsed time. If you use a standard 'h', the counter resets to 0 after reaching 24 hours. The bracketed format ensures that 25 hours is displayed accurately as '25:00:00'.

Where does the number 86,400,000 come from?

It represents the total number of milliseconds in a single day. The calculation is 24 (hours) × 60 (minutes) × 60 (seconds) × 1000 (milliseconds).

Can I use this same formatting method in Microsoft Excel or WPS Spreadsheet?

Yes, the custom format string [h]:mm:ss works exactly the same way in Excel and WPS Spreadsheet for displaying elapsed time that is stored as a fraction of a day.