I am trying to find the difference between two dates. I need the difference in Years, months, and days all in the same calculation. I can’t get the datediff() function to do what I want. Does anyone have a workaround I can use. Thanks
![]() |
Patch reliability is unclear, but widespread attacks make patching prudent. Go ahead and patch, but watch out for potential problems. |
SIGN IN | Not a member? | REGISTER | PLUS MEMBERSHIP |
-
Date Calculator
Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Date Calculator
- This topic has 12 replies, 3 voices, and was last updated 23 years, 11 months ago.
Viewing 0 reply threadsAuthorReplies-
WSMarkJ
AskWoody LoungerMay 30, 2001 at 10:01 pm #527852Edited (several times – and then several times again) by MarkJ to fix a few small errors in the code
You could write a custom function (or functions) to accomplish your purpose. You’ll inevidably find yourself needing the DateDiff() function in the process.
You’ll probably want to so something like the following: (it may not be perfect, but it’s in the right direction)
Function TimeBetweenDates(Startdate As Date, EndDate As Date) As String 'Written by Mark S. Johnston (Markjsc@yahoo.com) '5/30/2001 'Switch the dates in case the StartDate comes 'after the EndDate If Startdate > EndDate Then Dim tmpDate As Date tmpDate = EndDate EndDate = Startdate Startdate = tmpDate End If Dim YearDiff As Long Dim MonthDiff As Long Dim DayDiff As Long 'Calculate Year If Format(Startdate, "mm/dd") 0 Then If Format(Startdate, "mm") > Format(EndDate, "mm") Then MonthDiff = 12 - Abs(DatePart("m", EndDate) - DatePart("m", Startdate)) Else MonthDiff = Abs(DatePart("m", EndDate) - DatePart("m", Startdate)) - 1 End If Else If Format(Startdate, "mm") > Format(EndDate, "mm") Then MonthDiff = 12 - Abs(DatePart("m", EndDate) - DatePart("m", Startdate)) Else MonthDiff = Abs(DatePart("m", EndDate) - DatePart("m", Startdate)) End If End If 'Calculate Day If MonthDiff = 0 Then DayDiff = Abs(DatePart("y", EndDate) - DatePart("y", Startdate)) Else DayDiff = Abs(DatePart("d", EndDate) - DatePart("d", Startdate)) End If 'Return Results TimeBetweenDates = YearDiff & " Years, " & _ MonthDiff & " Months, " & _ DayDiff & " Days" End Function
HTH
-
WSLarinL
AskWoody Lounger -
WSMarkJ
AskWoody Lounger -
WSLarinL
AskWoody Lounger -
WSMarkJ
AskWoody Lounger -
WSLarinL
AskWoody LoungerMay 30, 2001 at 7:10 pm #527867Thanks,
I have been doing some more work with it and found another problem. If the start date (we’ll call it birthday) has already happened for the current calendar year then it seems to work fine. If the Birthday has not happened yet during the current calendar year. It calculates wrong. I am checking a couple of things to see what the problem is.
-
WSMarkJ
AskWoody Lounger -
WSLarinL
AskWoody LoungerMay 30, 2001 at 9:05 pm #527885 -
WSMarkJ
AskWoody LoungerMay 30, 2001 at 10:14 pm #527889 -
WSLarinL
AskWoody Lounger -
WSStephenElms
AskWoody Lounger -
WSMarkJ
AskWoody Lounger
-
-
-
-
Viewing 0 reply threads -

Plus Membership
Donations from Plus members keep this site going. You can identify the people who support AskWoody by the Plus badge on their avatars.
AskWoody Plus members not only get access to all of the contents of this site -- including Susan Bradley's frequently updated Patch Watch listing -- they also receive weekly AskWoody Plus Newsletters (formerly Windows Secrets Newsletter) and AskWoody Plus Alerts, emails when there are important breaking developments.
Get Plus!
Welcome to our unique respite from the madness.
It's easy to post questions about Windows 11, Windows 10, Win8.1, Win7, Surface, Office, or browse through our Forums. Post anonymously or register for greater privileges. Keep it civil, please: Decorous Lounge rules strictly enforced. Questions? Contact Customer Support.
Search Newsletters
Search Forums
View the Forum
Search for Topics
Recent Topics
-
24H2 Installer – don’t see ption for non distructive install
by
JP
2 hours, 51 minutes ago -
Asking Again here (New User and Fast change only backups)
by
thymej
9 hours, 3 minutes ago -
How much I spent on the Mac mini
by
Will Fastie
3 hours, 52 minutes ago -
How to get rid of Copilot in Microsoft 365
by
Lance Whitney
51 minutes ago -
Spring cleanup — 2025
by
Deanna McElveen
14 hours, 55 minutes ago -
Setting up Windows 11
by
Susan Bradley
2 hours, 6 minutes ago -
VLC Introduces Cutting-Edge AI Subtitling and Translation Capabilities
by
Alex5723
10 hours, 23 minutes ago -
Powershell version?
by
CWBillow
11 hours, 16 minutes ago -
SendTom Toys
by
CWBillow
5 hours, 56 minutes ago -
Add shortcut to taskbar?
by
CWBillow
15 hours, 11 minutes ago -
Sycophancy in GPT-4o: What happened
by
Alex5723
1 day, 7 hours ago -
How can I install Skype on Windows 7?
by
Help
1 day, 6 hours ago -
Logitech MK850 Keyboard issues
by
Rush2112
13 hours, 11 minutes ago -
We live in a simulation
by
Alex5723
1 day, 21 hours ago -
Netplwiz not working
by
RetiredGeek
1 day, 8 hours ago -
Windows 11 24H2 is broadly available
by
Alex5723
2 days, 10 hours ago -
Microsoft is killing Authenticator
by
Alex5723
21 hours, 45 minutes ago -
Downloads folder location
by
CWBillow
2 days, 16 hours ago -
Remove a User from Login screen
by
CWBillow
1 day, 12 hours ago -
TikTok fined €530 million for sending European user data to China
by
Nibbled To Death By Ducks
2 days, 7 hours ago -
Microsoft Speech Recognition Service Error Code 1002
by
stanhutchings
2 days, 7 hours ago -
Is it a bug or is it expected?
by
Susan Bradley
9 hours, 50 minutes ago -
Image for Windows TBwinRE image not enough space on target location
by
bobolink
2 days, 6 hours ago -
Start menu jump lists for some apps might not work as expected on Windows 10
by
Susan Bradley
1 day, 6 hours ago -
Malicious Go Modules disk-wiping malware
by
Alex5723
2 days, 20 hours ago -
Multiple Partitions?
by
CWBillow
2 days, 21 hours ago -
World Passkey Day 2025
by
Alex5723
17 hours, 22 minutes ago -
Add serial device in Windows 11
by
Theodore Dawson
4 days, 5 hours ago -
Windows 11 users reportedly losing data due forced BitLocker encryption
by
Alex5723
2 days, 6 hours ago -
Cached credentials is not a new bug
by
Susan Bradley
4 days, 10 hours ago
Recent blog posts
Key Links
Want to Advertise in the free newsletter? How about a gift subscription in honor of a birthday? Send an email to sb@askwoody.com to ask how.
Mastodon profile for DefConPatch
Mastodon profile for AskWoody
Home • About • FAQ • Posts & Privacy • Forums • My Account
Register • Free Newsletter • Plus Membership • Gift Certificates • MS-DEFCON Alerts
Copyright ©2004-2025 by AskWoody Tech LLC. All Rights Reserved.