function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
lodoss1118lodoss1118 

Need help with calculating expiry date that handles leap year

hi i am trying create a formula field that calculates that expiry date from a start date and term

 

i got something like

 

startDate + terms * 30.4375

 

but it has some weird results? and does not handle leap years

 

anyone have a better formula :@

Steve :-/Steve :-/

What are the datatypes of the fields that you are using?  Date, DateTime, Number, Picklist, etc.  What kind of result are your trying to display?  a Date, a DateTime, a Number?

lodoss1118lodoss1118

the expiryDate is a date field

 

start date is a date field

terms is a number field measured in months i.e 1, 4, 12 etc..

 

i am trying to calculate the expiry date from start date and terms entered?

 

so if someone enters start date: 31/02/2011 terms: 1

then expiry date: 28/02/2011

and should handle leap years if possible :@

 

another example:

start date: 28/02/2011 terms:12

expiry date: 28/02/2012

Steve :-/Steve :-/

ouch...  okay that one is not gonna be easy if you need to make adjustments for number of days in the month(28, 30, 31) and also factor in leap year.  

regger118regger118

i think i'll handle this in apex will be easier