Computer Learning Zone CLZ Access Excel Word Windows

It is not enough to have a good mind. The main thing is to use it well.

-Rene Descartes
 
Home   Courses   Index   Templates   Seminars   TechHelp   Forums   Help   Contact   Join   Order   Logon  
 
Home > Code Vault > Generic VBA > Date Time > How Long >
How Long
By Richard Rost   Richard Rost on LinkedIn Email Richard Rost   4 years ago

This function will return how long since or how long until such as "3 days ago" or "in 34 minutes, 12 seconds"

UPDATE (2021-02-22): Fixed some bugs and added weeks (w)

UPDATE (2022-03-16): Added T2 as an optional second date/time value. If you don't specify it, then Now() will still be used to give you the current system date/time. However, if you want to get the difference between two date/time values, you can now specify T2 and it will calculate that for you.

And yes, I've noticed that VBA ignores your system date format. Even though I recently switched everything I have over to the ISO Date Standard Format, Access VBA doesn't seem to care. It still wants dates as mm/dd/yy. Not much I can do there.



Click here for the function's VBA source code: How Long VBA Code - Gold Members only
 


Usage assuming today's date is 8/23/2020
(min and sec are advancing as I'm typing this, but you get the point):

HowLong(#8/1/2018#)                           2 years ago
HowLong(#8/1/2020#)                           22 days ago
HowLong(#8/22/2020 10pm#)                     17 hours ago
HowLong(#8/22/2020 10pm#, True)               17 hours, 30 minutes, 23 seconds ago
HowLong(#8/22/2020 10pm#, True, "hn")         17 hours, 30 minutes ago
HowLong(#8/1/2018#, True)                     2 years, 22 days, 15 hours, 39 minutes, 14 seconds ago
HowLong(#8/1/2018#, True, "ymdhn")            2 years, 22 days, 15 hours, 39 minutes ago
HowLong(#8/1/2018#, True, "ymdhn", False)     2 years, 22 days, 15 hours, 39 minutes
HowLong(#6/1/2018#, True, "ym", False, True)  2 yr, 2 mo
HowLong(#1/1/2010#, False, "mmdd")            127 months ago
HowLong(#1/1/2010#, True, "mmdd")             127 months, 22 days ago
HowLong(#1/1/2025#)                           in 4 years
HowLong(#1/1/2025#, True, "ymdh")             in 4 years, 4 months, 8 days, 8 hours
HowLong(#1/1/2021#, True, "hn", True, True)   in 3128 hr, 9 min


UPDATE (2022-03-16): With T2 now added:

HowLong(#8/1/2018#,,,,,#1/1/2022#)            3 years ago
HowLong(#8/1/2018#, True,,,,#1/1/2022#)       3 years, 5 months ago
HowLong(#8/1/2018#, True,"ymd",,,#1/13/2022#) 3 years, 5 months, 12 days ago

Get it? Good.

 

Comments for How Long
 
Age Subject From
2 yearsHow LongMohiuddin Ahmed
2 yearsHowLong UpdatedRichard Rost
3 yearsHowLong Bug Fix AgainLeah Bacani
3 yearsHowLong Bug FoundRichard Rost

 

Start a NEW Conversation
 
Only students may post on this page. Click here for more information on how you can set up an account. If you are a student, please Log On first. Non-students may only post in the Visitor Forum.
 
Subscribe
Subscribe to How Long
Get notifications when this page is updated
 
 
 
 

The following is a paid advertisement
Computer Learning Zone is not responsible for any content shown or offers made by these ads.
 

Learn
 
Access - index
Excel - index
Word - index
Windows - index
PowerPoint - index
Photoshop - index
Visual Basic - index
ASP - index
Seminars
More...
Customers
 
Login
My Account
My Courses
Lost Password
Memberships
Student Databases
Change Email
Info
 
Latest News
New Releases
User Forums
Topic Glossary
Tips & Tricks
Search The Site
Code Vault
Collapse Menus
Help
 
Customer Support
Web Site Tour
FAQs
TechHelp
Consulting Services
About
 
Background
Testimonials
Jobs
Affiliate Program
Richard Rost
Free Lessons
Mailing List
PCResale.NET
Order
 
Video Tutorials
Handbooks
Memberships
Learning Connection
Idiot's Guide to Excel
Volume Discounts
Payment Info
Shipping
Terms of Sale
Contact
 
Contact Info
Support Policy
Mailing Address
Phone Number
Fax Number
Course Survey
Email Richard
[email protected]
Blog RSS Feed    YouTube Channel

LinkedIn
Copyright 2024 by Computer Learning Zone, Amicron, and Richard Rost. All Rights Reserved. Current Time: 3/28/2024 5:04:07 AM. PLT: 0s
Keywords: code vault generic vba howlong how long until how long ago  PermaLink  How Long