Changing Date Format Using PeopleCode

Your rating: None Average: 3.9 (11 votes)

Peoplesoft provides a function called as "DateTimeToLocalizedString" to change date from one format into another.

Following is syntax used to achiev this.

DateTimeToLocalizedString({datetime | date}, [Pattern])

Param1 : Variable of Date Datatype
Param2 : Date format which you want for example "dd/MM/yyyy".

If you have Param1 of type string then use function "DateValue" to convert that string to Date.

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!


Have a question? Please ask it on the forum instead.
Lepa's picture
User offline. Last seen 2 years 26 weeks ago. Offline
Joined: 06/23/2008
Posts: 591
Re: Changing Date and Date time formate example

Here is an example on how we can apply the above function.

%date in as 2008-08-29 out as 20080829:

&date = DateTimeToLocalizedString(%Date, "yyyyMMdd");

%Datetime in as 2008-08-19- out as 20080828-171209:

&datetime = DateTimeToLocalizedString(%Datetime, "yyyyMMdd-HHmmss");

Give back to the community and help it grow!
* Help with unanswered forum questions and issues
* Register or login to share your knowledge at your own blog

gwulfwud's picture
User offline. Last seen 10 years 33 weeks ago. Offline
Joined: 05/07/2009
Posts: 7
Re: Changing Date Format Using PeopleCode

So I have a question.

I've been trying to get the year from a date value.

&LastDateWorkedYear = &rs1(&I).TIA_VW.LAST_DATE_WORKED.Value;
&LastDateWorkedYear = Year(&LastDateWorkedYear);

I get this error:

An invalid date has been encountered in a PeopleCode program.

Hari_aindian's picture
User offline. Last seen 7 years 9 weeks ago. Offline
Joined: 08/02/2010
Posts: 84
Re: Changing Date Format Using PeopleCode

Are you sure that the &LastDateWorkedYear has a valid date?

Year(DATE) function will work only if the provided DATE is a vaild date format. If it is a Date time field then it wont work. Or else declare &LastDateWorkedYear as date and then try.

pls do let me know which one resolves your issue.