Fix Microsoft Project Application.DateDifference Returns Zero in VBA
Question details
The user is experiencing an issue where the VBA Application.DateDifference function incorrectly returns zero, causing division-by-zero and overflow errors in macros.
- Product
- Microsoft Project
- Device & OS
- not provided
- Scenario
- Running VBA scripts to calculate working time differences based on project calendars in Microsoft Project version 2409.
- Observed behavior
- Application.DateDifference returns 0 instead of the correct time difference, whereas it worked correctly in version 2108. The native DateDiff function works but ignores project calendars.
Ensure you have access to the VBA Editor in Microsoft Project and verify that your project calendar is properly configured with valid working times.
Step Through VBA Code and Inspect Date Variables
Use the built-in VBA debugger to pause code execution and verify the exact date values being passed into the Application.DateDifference function.
Often, functions return zero when invalid or unexpected date values are passed into them. Stepping through the code allows you to monitor variables in real-time.
Press ALT + F11 while in Microsoft Project to open the Visual Basic for Applications (VBA) Editor.
Locate the macro containing your Application.DateDifference function. Click in the left margin next to the code line to insert a breakpoint (a red dot will appear).
Run the macro. When execution pauses at the breakpoint, press F8 to step through the code line by line.
Hover your mouse over the date variables used in the function, or use the Immediate Window (CTRL + G) to print their values and ensure they are valid dates.
Verify Project Calendar and Configuration Settings
Differences in edition, build, or calendar settings can cause calculation failures. Testing with a standard calendar helps isolate the root cause.
Review Trust Center and Security Policies
Strict security settings or macro policies in newer builds might interfere with advanced application functions.
Try WPS Office for Your Data Management and Documentation Needs
While Microsoft Project handles specialized complex project scheduling, you can use WPS Office as a lightweight, free alternative for tracking project tasks, timelines, and budgets using highly familiar spreadsheets and documents.
- 1. Download WPS Office: Visit the official WPS website to download and install the free WPS Office suite on your device.
- 2. Explore Project Templates: Open WPS Spreadsheets, click on 'New', and browse the template library for Gantt charts or project management trackers.
- 3. Manage Project Data: Import your existing Excel or CSV project data to easily track timelines and calculate date differences using standard spreadsheet functions.

Frequently Asked Questions
Why does DateDiff work but Application.DateDifference returns 0?
The native VBA DateDiff function only calculates standard calendar time differences regardless of working hours. Application.DateDifference calculates working time based on a specific project calendar, which may return 0 if the calendar is missing, misconfigured, or affected by a build-specific bug in version 2409.
How do I handle division-by-zero errors in my Microsoft Project VBA macro?
You should add error-handling routines using 'On Error GoTo' or use an 'If' statement to conditionally check if the Application.DateDifference result is zero before using it as a denominator in a division operation.
Can macro security settings affect specific VBA functions like DateDifference?
Yes, strict Trust Center policies in newer MS Project builds can sometimes restrict certain application-level methods from executing properly. Ensuring your macro file is saved in a Trusted Location can help bypass these restrictions.




