Calculating Dates in VBA

  • Thread starter Thread starter Squid
  • Start date Start date
S

Squid

I want to write some code that will calculate a date. I
need to calcuate an expiration date. The expiration date
will always be 1 year minus a day from the effective
date. So if the effective date = 6/1/2003, then the
expiration date = 5/31/04. I can do this pretty easily
within an excel worksheet, but I would like this to
happen with code.

Thanks
Mike
 
Its actually quite easy in VBA. A function like this for example:

Function ExpirationDate(StartDate As Date) As Date
ExpirationDate = DateAdd("yyyy", 1, StartDate) - 1
End Function

Used like:

?ExpirationDate(DateSerial(2003,6,1))
5/31/2004
 
Thank you... knew if was simple. .


Juan Pablo González said:
Its actually quite easy in VBA. A function like this for example:

Function ExpirationDate(StartDate As Date) As Date
ExpirationDate = DateAdd("yyyy", 1, StartDate) - 1
End Function

Used like:

?ExpirationDate(DateSerial(2003,6,1))
5/31/2004
 
Back
Top