How to Convert Date Format using Peoplecode in Peoplesoft

How to Convert Date Format using Peoplecode in Peoplesoft

How to Convert Date Format using Peoplecode in Peoplesoft by function  is DateTimeToLocalizedString of peoplesoft

&StartDT = DateTimeToLocalizedString(DERIVED_TT.KTB_START_DT, “yyyyMMdd”);

&DT= DateTimeToLocalizedString(%date, “dd-MM-yyyy”);

 

For example on how to apply the above function.

%date in as 2018-09-07 out as 20180907:
&date = DateTimeToLocalizedString(%Date, “yyyyMMdd”);
%Datetime in as 2018-09-07.15.41.000000 out as 20180907-154109:
&datetime = DateTimeToLocalizedString(%Datetime, “yyyyMMdd-HHmmss”);

 

Date and Time in Meta-SQL

For input or output of the current date or time:

  • %CurrentDateIn

The %CurrentDateIn meta-SQL variable expands to a platform-specific SQL substring representing the current date in the Where clause of a SQL Select or Update statement, or when the current date is passed in an Insert statement.

  • %CurrentDateOut

The %CurrentDateOut meta-SQL variable expands to platform-specific SQL for the current date in the Select clause of a SQL query.

  • %CurrentDateTimeIn

The %CurrentDateTimeIn meta-SQL variable expands to a platform-specific SQL substring representing the current datetime in the Where clause of a SQL Select or Update statement, or when the current date time is passed in an Insert statement.

  • %CurrentDateTimeOut

The %CurrentDateTimeOut meta-SQL variable expands to platform-specific SQL for the current datetime in the Select clause of a SQL query.

  • %CurrentTimeIn

The %CurrentTimeIn meta-SQL variable expands to a platform-specific SQL substring representing the current time in the Where clause of a SQL Select or Update statement, or when the current time is passed in an Insert statement.

  • %CurrentTimeOut

The %CurrentTimeOut meta-SQL variable expands to platform-specific SQL for the current time in the Select clause of a SQL query.

For input or output of any date or time:

  • %DateIn

The %DateIn meta-SQL variable expands into platform-specific SQL syntax for the date. Use %DateIn whenever a date literal or Date bind variable is used in a comparison in the Where clause of a Select or Update statement, or when a Date value is passed in an Insert statement.

Restrictions Using COBOL

You can only use string literals when using this construct in COBOL. You cannot use it with bind parameters in COBOL. For example, the following works in COBOL:

The following SQL fails:

  • %DateOut

The %DateOut meta-SQL variable expands to either a platform-specific SQL substring or datetime value, depending on the database platform, representing a datetime column in the Select clause of a SQL query

  • %DateTimeIn

The %DateTimeIn meta-SQL variable expands to platform-specific SQL for a DateTime value in the Where clause of a SQL Select or Update statement, or when a DateTime value is passed in an Insert statement.

  • %DateTimeOut

Restrictions Using COBOL

You can only use string literals when using this construct in COBOL. You cannot use it with bind parameters in COBOL. For example, the following works in COBOL:

The following SQL fails:

  • %TimeIn

%TimeIn expands to platform-specific SQL for a Time value in the Where clause of a SQL Select or Update statement, or when a time value is passed in an Insert statement.

Restrictions Using COBOL

You can only use string literals when using this construct in COBOL. You cannot use it with bind parameters in COBOL. For example, the following works in COBOL:

The following SQL fails:

  • %TimeOut

When  input date/time goes in the WHERE clause (conditions) and output date/time goes in the SELECT clause (returned data).

For input/output of a null date/time:

  • %DateNull
  • %DateTimeNull
  • %TimeNull

For getting part of a date/time:

  • %DatePart gets the date
  • %TimePart gets the time

For date arithmetic:

  • %DateAdd(date_from, days_to_add) gives the resulting date. You can use negative numbers to get a past date. So this is also the DateSubtract function.

  • %DateDiff(date_from, date_to) gives the difference between two dates in days

The following usage is illegal (always use %Datein for inputting date literals):

  • %DateTimeDiff(date_from, date_to) gives the difference between two date/times in minutes

The following example returns the difference in hours between the current datetime and the requested datetime:

The following example returns the difference in minutes:

 

 

References:

http://peoplesoft.wikidot.com/date-and-time-in-meta-sqlhttps://docs.oracle.com/cd/E57990_01/pt853pbh2/eng/pt/tape/langref_UsingApplicationEngineMeta-SQL-0771d9.html#topofpage

Posted in Peoplecode.