Access 97: How to subtract one date/time from another?

  • Thread starter Thread starter Anthony Burner
  • Start date Start date
A

Anthony Burner

I want to create a field that is auto populated by the
current date and time and once this field has been
populated, it cannot be modified. I want the user to be
able to type a past date and time into a field and have
Access print a report that gives me the difference
between those two dates/times in days/hours/minutes. How
is this done?

Thank you.
 
For the first part, simply create a date/time field in the table and set its
default value to Now(). Provided you ensure that the users don't have access
to the tables then they won't be able to change it. If you need to display
this field on a form then lock and disable the control.

For the report, I would first create a query based on the table an use the
query as the basis of the report. You can use the DateDiff function to get
the days, hours and minutes between the dates:

Difference in days: Days: DateDiff("d",[Date2],[Date1])
Hours: Hrs: DateDiff("h",[Date2],[Date1])-[Days]*24
Minutes: Mins:
DateDiff("n",[Date2],[Date1])-([Days]*24+[Hrs])*60
 
Thank you very much. I appreciate your help.



-----Original Message-----
For the first part, simply create a date/time field in the table and set its
default value to Now(). Provided you ensure that the users don't have access
to the tables then they won't be able to change it. If you need to display
this field on a form then lock and disable the control.

For the report, I would first create a query based on the table an use the
query as the basis of the report. You can use the DateDiff function to get
the days, hours and minutes between the dates:

Difference in days: Days: DateDiff("d",[Date2],[Date1])
Hours: Hrs: DateDiff("h",[Date2], [Date1])-[Days]*24
Minutes: Mins:
DateDiff("n",[Date2],[Date1])-([Days]*24+[Hrs])*60


Anthony Burner said:
I want to create a field that is auto populated by the
current date and time and once this field has been
populated, it cannot be modified. I want the user to be
able to type a past date and time into a field and have
Access print a report that gives me the difference
between those two dates/times in days/hours/minutes. How
is this done?

Thank you.


.
 
Back
Top