Setting a Date to Null in PeopleCode
To set a date to null in PeopleCode either use the SetDefault() function (deprecated) or the SetDefault field method
Using the function:
SetDefault(YOUR_RECORD.DT_FIELD);
Using the field method If you are in the current context:
YOUR_RECORD.DT_FIELD.SetDefault();
Using the field method if you are not in the current context using a field object:
Local Field &fldDateExample;/* Code to set your &fldDateExample object */&fldDateExample.SetDefault();
Not intuitive but it works.
Setting a Date to Null in PeopleCode (Part II - another way!)
There is also another way to set a date to null via PeopleCode! In some cases, using SetDefault() to blank out a field is not what we're after, as there may be a default for the field! The only other way (to my knowledge) is this:
RECNAME.DATE_FIELD.Value = "";
.Value is the KEY here. Not including .Value will throw Syntax errors in App Designer when you try to assign the date field to "" and save your program.
Getting the time in the format HHMMSS from the current time:
Getting time in the format HHMMSS from the current time:
Local &strCurrentTime;&strCurrentTime = Substring(Substitute(String(TimePart(%Datetime)), ".", ""), 1, 6);
This takes the time part of the current date time on the application server, replaces the dot (.) seperators with blanks, and returns only the first 6 characters (hhmmss) ignoring the millisecond part. This returns say a time of 11.52.00.000000 as 115200. I used this in an application to rename a file with a date & time stamp.
Use %DateOut to Get Dates from SQL into a Date Variable
If you are using a date that is returned from SQL and storing it into a date variable, make sure you wrap your date with %DateOut in your SQL, otherwise PeopleSoft will throw an invalid date error.