Access 2003 Date format

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a table designed to reflect employees, Vacation information and
attendance information. I would like to show the years of service in the
company in a field in the form. How? Please help. Your assistance would be
much appreciated. I am new at this development programming in access
 
Mickey,

There are a couple of ways you can do that; an accurate way, and an
inaccurate (yet possibly acceptable) way.

The inaccurate way is to place the following pseudo-code into the
txtYearsofService textbox's ControlSource property:
=DateDiff("yyyy", [DateStarted], Date())
This will only return the number of years.

The accurate way is to place the following pseudo-code into the
txtYearsofService textbox's ControlSource property:
=Diff2Dates("dmy",[DateStarted], Date(), False)
This will (selectively) return the number of years, months, days, hours,
minutes and seconds.

....but before you try this last sugestion, download the code found at
http://www.pacificdb.com.au/MVP/Code/Diff2Dates.htm, and place it in a
standard module.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
There's also an intermediate possibility.

=DateDiff("yyyy", [DateStarted], Date()) will return the wrong answer if the
anniversary of DateStarted hasn't yet occurred this year. For example, if
someone starts 2006-12-31, on 2007-01-01 DateDiff("yyyy", [DateStarted],
Date()) will return 1.

To correct for that, use

=DateDiff("yyyy", [DateStarted], Date()) - _
IIf(Format(Date(), "mmdd") < Format([DateStarted], "mmdd"), 1. 0)


--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Graham R Seach said:
Mickey,

There are a couple of ways you can do that; an accurate way, and an
inaccurate (yet possibly acceptable) way.

The inaccurate way is to place the following pseudo-code into the
txtYearsofService textbox's ControlSource property:
=DateDiff("yyyy", [DateStarted], Date())
This will only return the number of years.

The accurate way is to place the following pseudo-code into the
txtYearsofService textbox's ControlSource property:
=Diff2Dates("dmy",[DateStarted], Date(), False)
This will (selectively) return the number of years, months, days, hours,
minutes and seconds.

...but before you try this last sugestion, download the code found at
http://www.pacificdb.com.au/MVP/Code/Diff2Dates.htm, and place it in a
standard module.

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia

Mickey said:
I have a table designed to reflect employees, Vacation information and
attendance information. I would like to show the years of service in the
company in a field in the form. How? Please help. Your assistance
would be
much appreciated. I am new at this development programming in access
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top