Add to Date using PeopleCode

Your rating: None Average: 3.4 (12 votes)

I came across the below PeopleCode built-in function when trying to find a way to add a month to %date. So, here it is as PeopleSoft explaines it.
My code ended up being like this :

/*Adding one month to system date*/
AddToDate(%date, 0,1,0);

Syntax
AddToDate(date, num_years, num_months, num_days)
Description
Use the AddToDate function to add the specified number of years, months, and days to the date provided.

Suppose, for example, that you want to find a date six years from now. You could not just multiply 6 times 365 and add the result to today’s date, because of leap years. And, depending on the current year, there may be one or two leap years in the next six years. AddToDate takes care of this for you.
You can subtract from dates by passing the function negative numbers.

Considerations Using AddToDate
When you are adding one month to the date provided, and the date provided is the last day of a month, and the next month is shorter, the returned result is the last day of the next month.
For example, in the following, &NewDate is 29/02/2004:
&NewDate = AddToDate("31/01/2004", 0, 1, 0);
When you are adding one month to the date provided, and the date provided is the last day of a month, and the next month is longer, the returned result is not the last day of the next month.
For example, in the following, &NewDate is 29/03/2004.
&NewDate = AddToDate("29/02/2004", 0, 1, 0)

Please try to help out with unanswered topics on the forum. Chances are you have had the same issue/question some time in your IT career!

Comments

Have a question? Please ask it on the forum instead.
Guest's picture
Guest (not verified)
Re: Add to Date using PeopleCode

i need to change the probation date according to effective date which is in another record.how i can do

Guest's picture
Guest (not verified)
Re: Add to Date using PeopleCode

If the number of days goes into the next year this does not return the correct date. It assumes a 360 day year.

Hari_aindian's picture
User offline. Last seen 5 years 26 weeks ago. Offline
Joined: 08/02/2010
Posts: 84
Re: Add to Date using PeopleCode

Have you tried using %DateAdd function.

Find the number of days you wanna add for ex:

%DateDiff(Probation_dt,hire date);

then try using %DateAdd function and let me know whether it helps you.