Dates problem

neilmcmor

Registered User.
Local time
Today, 06:10
Joined
Aug 9, 2007
Messages
70
I have 2 dates in a form, (First date & Last date already there when form opens), from which I want to display the difference in years, months & days. I have found several completely different methods for this on the net however I am still not getting it correct. The best I could find was some code by Pat Harman from 2002 however he suggested looking at a sample database on here which no longer can be found. I would want it to calculate this when the form opens. Would I just put my code in the form open event?
 
Depends on what you want to achieve. If you just want to calc' the dates at run-time, yes, add an unbound text box and a wee bit of code and you will have it.

Code:
Example for a year
=DateDiff("yyyy",[txtFirstDate],[txtSecondDate])

Example for a week
=DateDiff("w",[txtFirstDate],[txtSecondDate])

Example for days
=DateDiff("y",[txtFirstDate],[txtSecondDate])

txtFirstDate would be the text box with the first date and txtSecondDate would be the name of the text box with the second date.

If you wish to store the value, that is a slightly different approach. But not needed if all you would ever want to do is calc' the difference.
 

Users who are viewing this thread

Back
Top Bottom