You are viewing this site as a guest. You can still ask questions and help others! Join our Dev2Dev IT Community to receive your own blog, share your knowledge, and much more.

How to change date format in people code

9 replies [Last post]
suadha's picture
User offline. Last seen 11 years 44 weeks ago. Offline
Joined: 07/22/2008
Posts: 1

Hi All,
can any body tell me how to change format of the date to 'yymmdd' in people code. this i can achieve in
sqr by using edit()function.is there any built in function in peoplecode to change the date format.

Thanks in advance,
sudha

Lepa's picture
User offline. Last seen 1 year 31 weeks ago. Offline
Joined: 06/23/2008
Posts: 591
Re: How to change date format in people code

Is that a field displayed on the page? I don't think there is a build in function that does that for you. But if you are pulling the date from the database then why not use %dateout.

You can also use SQLExec and to_char(date_field, 'yymmdd').

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

Guest's picture
Guest (not verified)
Re: How to change date format in people code

Thanks for your reply. actually my requirement is generating an outbound interface using application engine.
and client want the OUTPUT file name should be concatenated with sysdate in format'yymmdd'.
Every day this file has to run and the file name should be changed depending on the run date.for this to get
a sysdate i am using %Date() function but how can i change date format?

Thanks,
sudha

Lepa's picture
User offline. Last seen 1 year 31 weeks ago. Offline
Joined: 06/23/2008
Posts: 591
Re: How to change date format in people code

How about this?

SQLExec("select to_char(sysdate, 'yymmdd') from dual", &formatedDate);

and then append it to your file name as such:

&myFileName = &myFileName || "_" || &formatedDate;

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

Guest's picture
Guest (not verified)
Re: How to change date format in people code

Thank you so much for your reply

Nitin's picture
User offline. Last seen 5 years 3 weeks ago. Offline
Joined: 06/30/2008
Posts: 73
Re: How to change date format in people code

Proably this can also work even though i haven't tested it.

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

Thanks
Nitin Bhatia

Lepa's picture
User offline. Last seen 1 year 31 weeks ago. Offline
Joined: 06/23/2008
Posts: 591
Re: How to change date format in people code

Nitin, it sure does work, here is an example on how to use the date and date time format function http://www.compshack.com/peoplecode/changing-date-format-using-peoplecod...

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

navinsahay's picture
User offline. Last seen 6 years 7 weeks ago. Offline
Joined: 04/24/2009
Posts: 6
Re: How to change date format in people code

Hi! All,

There is one built-in function "DateTimeToLocalizedString". You can use this if you want to change the date format through people code for your PIA pages.

How to use:

Example 1:
&String = DateTimeToLocalizedString(&Date, "M/d/y");
/* if you are picking the date from any record field and using &Date for that field */

Example 2:
&String = DateTimeToLocalizedString(%Date, "M/d/y");
/* if you want to pick the system date and want to use it on your page with different formats. */

Note: Here 'd' for date and 'y' for year both must be in smaller letters only. And, 'M' for months should be in Caps.

I hope this will help you.

Warm Regards,
Navin Sahay

Guest's picture
Guest (not verified)
Re: How to change date format in people code

current date minus one

Guest's picture
Guest
Re: How to change date format in people code

Hi all,
I used DateTimeToLocalizedString to convert the date format, but the variable also gets converted to string which then messes up other functionality. If i convert this string variable back to Date or Datevalue it overrides the date format and goes back to original. How can i directly change the date format without changing it to string. TO_DATE(TO_CHAR) also does not respond.