By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,396 Members | 1,422 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,396 IT Pros & Developers. It's quick & easy.

Subtract one year accurately?

P: n/a
I have a timecard logging program in Access97 that I've used for a few
years now. Most of the year it works without problems. But...

Every January, when logging in the December cards, the data entry
person has to start including the year when typing, otherwise the card
is logged as NEXT December.

I started putting together a simple AfterUpdate function to reduce
keying errors, and it basically looks like this:

if [TCDate]>Now() then
[TCDate]=[TCDate]-365
endif

But then I realized that leap years will cause a one-day-off error.
Rather than re-invent the wheel, I'm hoping one of you nice people can
tell me a simpler way to subtract exactly one year from a keyed-in
date. Is there some sort of named function that I can use in place of
the "-365" bit, rather than write a long IF statement to test for
'year is divisible by 4' except when it's divisible by 100, etc.

I'm pretty sure I'll read the responses and slap my forehead, but I
can live with that. :)

Thanks in advance for any help!

Dennis
Nov 12 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On 10 Feb 2004 07:20:34 -0800, Dennis Kuhn wrote:
I have a timecard logging program in Access97 that I've used for a few
years now. Most of the year it works without problems. But...

Every January, when logging in the December cards, the data entry
person has to start including the year when typing, otherwise the card
is logged as NEXT December.

I started putting together a simple AfterUpdate function to reduce
keying errors, and it basically looks like this:

if [TCDate]>Now() then
[TCDate]=[TCDate]-365
endif

But then I realized that leap years will cause a one-day-off error.
Rather than re-invent the wheel, I'm hoping one of you nice people can
tell me a simpler way to subtract exactly one year from a keyed-in
date. Is there some sort of named function that I can use in place of
the "-365" bit, rather than write a long IF statement to test for
'year is divisible by 4' except when it's divisible by 100, etc.

I'm pretty sure I'll read the responses and slap my forehead, but I
can live with that. :)

Thanks in advance for any help!

Dennis


Dennis,
Don't slap too hard.. :-)

[TCDate]=DateAdd("yyyy",-1,[TCDate])

See VBA Help for info on DateAdd().
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
Nov 12 '05 #2

P: n/a
fredg <fg******@att.net> wrote in message news:<iw****************************@40tude.net>.. .


Dennis, Don't slap too hard.. :-)

[TCDate]=DateAdd("yyyy",-1,[TCDate])

See VBA Help for info on DateAdd().

D'oh! [Slap!!]

The worst part is that I _did_ see the DateAdd bit, but after a
cursory glance at the help for it, I assumed it wasn't really what I
was looking for. In actuality, I was only looking for one specific
type of solution, and didn't accept that this was a valid alternative.
Gotta loosen up this old brain of mine...

Oh, thanks very much!

Dennis
Nov 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.