Tuesday, October 22, 2013

Get the last day of the month with PeopleCode!

One nice thing to write the function to get "the last day of the month" in PeopleCode is that there is no restriction with the database platform.

Here is the easy how to:

   Local integer &year = Year(%Date);
   Local integer &month = Month(%Date);
   
   /* Get the last day of the month */
   If &month < 12 Then
      &last_day = Date3(&year, &month + 1, 1) - 1;
   Else
      &last_day = Date3(&year + 1, 1, 1) - 1;
   End-If;

Wednesday, October 2, 2013

Ez way to mask value in peoplecode

You can use this one line of code to mask sensitive data such as social security, bank account, etc.

Local string &_value = "123456789"; 
Local string &_masking_char = "*"; /* masking character */
Local integer &_digit_display = 4; /* number to display */
Local string &_new_value;

&_new_value = Rept(&_masking_char, Len(&_value) - &_digit_display) | Substring(&_value, (Len(&_value) - &_digit_display) + 1, Len(&_value));

Result:
&_new_value is *****6789


Get the First & Last Day of The Month In Oracle

Oracle figures if we can get the last day of the month using its handy LAST_DAY function, we should be able to figure out the first day, right?

Yep, here is one of many ways to get the first and last day of the month in Oracle.

Select  (last_day(:1)  - TO_CHAR(last_day(:1), 'DD')) + 1 as First_Day, last_day(:1) as last_Day from dual

Replace bind :1 to the actual date, then you get the result below: