Showing posts with label Dates. Show all posts
Showing posts with label Dates. Show all posts

Tuesday, March 4, 2014

Custom Display Date format

Date Format

In order to use a customized date format such as "January 14, 2014" in PeopleCode you need to use the function DateTimeToLocalizedString(&SupportDT, "MMM d, yyyy"); The second parameter is a pattern you define using any of the documented symbols found in the function documentation.
Local String &SupportText;
Local Date &SupportDT = %Date;
&SupportText = DateTimeToLocalizedString(&SupportDT, "MMM d, yyyy");
Thanks Ernie for sharing this one!

Wednesday, January 22, 2014

Peoplecode and the dates returned from oracle

The built in peoplecode function DATE() claims it needs the format YYYYMMDD however it must automatically strip special characters because if you pass in the standard format Oracle is returning dates in YYYY-MM-DD to this method it works fine.

Here is my sample code that passed and returned the expected values.

Sample

Local date &testDate;
Local number &testYear, &testMonth, &testDay, &testWeekday;
   MessageBox(0, "", 0, 0, " Mess with dates %1 ", &payCalendar.PAY_END_DT.Value);
&testDate = Date(&payCalendar.PAY_END_DT.Value);
&testYear = Year(&testDate);
&testMonth = Month(&testDate);
&testDay = Day(&testDate);
&testWeekday = Weekday(&testDate);
MessageBox(0, "", 0, 0, " date = %5 / Year=%1, Month=%2, Day=%3, Weekday=%4 ", &testYear, &testMonth, &testDay, &testWeekday, &testDate);

Output was


 Mess with dates 2013-01-07  (0,0)
 date = 2013-01-07 / Year=2013, Month=1, Day=7, Weekday=2  (0,0)

Tuesday, January 14, 2014

Null date in a Record


Today I was trying to create a new record that had a EFFDT and one other date field that needed to be NULL.  During the update oracle failed to identify null as a date and gave the error "ORA-01841: (full) year must be between -4713 and +9999, and not be 0".  The solution was to not set the date field to null but instead use Date function with the value 0.


   Local Record &rec = CreateRecord(Record.GENL_DEDUCTION);
   &rec.EMPLID.Value = &MCMADSJB.EMPLID.Value;
   &rec.COMPANY.Value = &MCMADSJB.company.value;
   &rec.DEDCD.Value = &MCMADSJB.company.value;
   If &MCMADSJB.effdt.value > &MCMADSMAP.effdt.value Then
      &rec.EFFDT.Value = Date(&MCMADSJB.effdt.value);
   Else
      &rec.EFFDT.Value = Date(&MCMADSMAP.effdt.value);
   End-If;
   &rec.DEDUCTION_END_DT.Value = Date(0);
   &result = &rec.Insert();

The Date(0) will correctly make the database field null.