• Skip to main content
  • Skip to primary sidebar
  • Home
  • Connect
  • Contact
  • About Us

BareFoot PeopleSoft

Oracle PeopleSoft Tips and Tricks

Tip 023: Function DateTimetoLocalizedString

March 21, 2018

PeopleCode | Mastering the date to string conversion function.

<< Previous  | Next >>

A. Introduction

The PeopleCode function ‘DateTimetoLocalizedString’ converts a date, time or date-time value into a formatted string. Most of the challenge in using this command comes from making sense of the date/time format parameter. There are at least fifteen symbols in the format pattern that each carry a special meaning. In addition, the parameters are case sensitive. An upper-case ‘M’ indicates a month while a lower-case ‘m’ indicates a minute.

Also, don’t confuse the format patterns of ‘DateTimetoLocalizedString’ with those used by the ‘TO_CHAR’ or ‘TO_DATE’ functions in Oracle SQL. The PeopleCode function uses a different ‘language’ to specify the format type.

 

B. DateTimetoLocalizedString in Practice

Below are a few examples of ‘DateTimetoLocalizedString’ using a date of 01/01/2001 and a time of 2:15 pm:

/* Set date-time to 1 January 2001, 2:15 pm */
Local datetime &srcDate = DateTime6(2001, 1, 1, 14, 15, 0);
Local string &dateString;

/* 1 Jan 2001 */
&dateString = DateTimeToLocalizedString(&srcDate, "d MMM yyyy");

/* 01 Jan 2001 */
&dateString = DateTimeToLocalizedString(&srcDate, "dd MMM yyyy");

/* 01/01/2001 */
&dateString = DateTimeToLocalizedString(&srcDate, "dd/MM/yyyy");

/* 01.01.01 */
&dateString = DateTimeToLocalizedString(&srcDate, "dd.MM.yy");

/* Monday 1 January 2001 */
&dateString = DateTimeToLocalizedString(&srcDate, "EEEE d MMMM yyyy");

/* Mon 1 Jan 2001 */
&dateString = DateTimeToLocalizedString(&srcDate, "EEE d MMM yyyy");

/* 20010101 */
&dateString = DateTimeToLocalizedString(&srcDate, "yyyyMMdd");

/* 2:15 PM */
&dateString = DateTimeToLocalizedString(&srcDate, "h:mm a");

/* 1415 */
&dateString = DateTimeToLocalizedString(&srcDate, "km");

/* 01/01/2001 2:15 PM */
&dateString = DateTimeToLocalizedString(&srcDate, "dd/MM/yyyy h:mm a");

 

See Also:
Tip 032: Summary of Date Functions
Tip 053: Function NumberToString

<< Previous  | Next >>

Filed Under: PeopleCode Tagged With: Date, String, Time

Primary Sidebar

Categories

  • Administration
  • Application Engine
  • BI Publisher
  • COBOL
  • Data Mover
  • PeopleCode
  • PeopleTools
  • Portal
  • PS Query
  • Security
  • SQL
  • Utilities

Copyright © 2023 Elimbah Consulting Ltd