Leap year date calculation

R

Rachel

I have a form we use for tracking annual policy
information. We enter the effective date and it
calculates the expiration date by adding 365 days.
Because of this being a leap year, any policy term that
crosses over 2/29/04 has an expiration date that is 1 day
short. This is causing all kinds of problems. Does
anyone have a solution? Here is the current code:
Private Sub WC_Exp_Can_Enter()
If [wc eff] > 0 Then
[wc exp/can] = [wc eff] + 365
End If
End Sub
 
R

Rick Brandt

Rachel said:
I have a form we use for tracking annual policy
information. We enter the effective date and it
calculates the expiration date by adding 365 days.
Because of this being a leap year, any policy term that
crosses over 2/29/04 has an expiration date that is 1 day
short. This is causing all kinds of problems. Does
anyone have a solution? Here is the current code:
Private Sub WC_Exp_Can_Enter()
If [wc eff] > 0 Then
[wc exp/can] = [wc eff] + 365
End If
End Sub

Use the DateAdd() function. It takes leap years into account.

Private Sub WC_Exp_Can_Enter()
If [wc eff] > 0 Then
[wc exp/can] = DateAdd("yyyy", 1, [wc eff])
End If
End Sub
 
A

Andi Mayer

I have a form we use for tracking annual policy
information. We enter the effective date and it
calculates the expiration date by adding 365 days.
Because of this being a leap year, any policy term that
crosses over 2/29/04 has an expiration date that is 1 day
short. This is causing all kinds of problems. Does
anyone have a solution? Here is the current code:
Private Sub WC_Exp_Can_Enter()
If [wc eff] > 0 Then
[wc exp/can] = [wc eff] + 365
End If
End Sub

add 1 to the year like:

[wc exp/can] =
dateserial(year([wc eff]) + 1,month([wc eff]),day([wc eff])

if month([wc eff])=2 AND day([wc eff])=29 then
[wc exp/can] = [wc exp/can] -1
' the 29th of a nonLeapYear would be the 1 of march
endif

If you expect an answer to a personal mail, add the word "manfred" to the first 10 lines in the message
MW
 
J

James Goodman

What about:

Private Sub WC_Exp_Can_Enter()
If [wc eff] > 0 Then
[wc exp/can] = DATEADD("yyyy", 1, [wc eff])
End If
End Sub

I think this will alleviate your problem...
 
R

Rachel

It worked!!! You guys are awesome. This was driving me
nuts.. Thank you very much
Rachel
-----Original Message-----
What about:

Private Sub WC_Exp_Can_Enter()
If [wc eff] > 0 Then
[wc exp/can] = DATEADD("yyyy", 1, [wc eff])
End If
End Sub

I think this will alleviate your problem...

--
James Goodman



I have a form we use for tracking annual policy
information. We enter the effective date and it
calculates the expiration date by adding 365 days.
Because of this being a leap year, any policy term that
crosses over 2/29/04 has an expiration date that is 1 day
short. This is causing all kinds of problems. Does
anyone have a solution? Here is the current code:
Private Sub WC_Exp_Can_Enter()
If [wc eff] > 0 Then
[wc exp/can] = [wc eff] + 365
End If
End Sub


.
 

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

Top