Reputation: 11
I'm new to Peoplesoft and just trying to set the current date field to previous Sunday and for that I have used the 'weekday' function but this is returning an integer value. How can I convert the returned integer value to the date? Can anyone help me out with this issue? Thanks in advance.
Upvotes: 1
Views: 2359
Reputation: 1
Here is the code:
%Date is used to retrieve SYSDATE. I have added a few comments to validate the result.
/* Code Begins Here */
Local date &dtSunday;
Local integer &i;
MessageBox(0, "", 0, 0, "SYSDATE - " | %Date);
MessageBox(0, "", 0, 0, "Previous Sunday - 28-June-2015");
&i = Weekday(%Date);
&dtSunday = AddToDate(%Date, 0, 0, - (&i - 1));
MessageBox(0, "", 0, 0, "Computed Sunday - " | &dtSunday);
/* Code Ends Here */
Here is the result:
SYSDATE - 2015-07-02 (0,0)
Previous Sunday - 28-June-2015 (0,0)
Computed Sunday - 2015-06-28 (0,0)
Upvotes: -1
Reputation: 11
Assuming that you want the last sunday, so for example today is 30/06/2015 then the previous sunday is 28/06/2015.
to do that you can use
Local date &dt = %Date;
Local number &num = Weekday(&dt);
WinMessage(Date(&dt - (&num - 1)), 0);
Weekday function returns number value from 1 (sunday) to 7 (saturday). So if you know the today's date (%date) then get the weekday from it.
If you want to get another date other than current date then use DateValue(date_str) where date_srt is the string value of the date you want.
another way of doing this is
SQLExec(select To_date(:1,'DD/MM/YYYY') - (To_Char(To_date(:1,'DD/MM/YYYY'), 'D') -1) from dual, &dtValue, &dtSunday);
substitute &dtValue to the date you want
visit http://peoplesoftdotnet.blogspot.com.au/ for more tips
Upvotes: 1
Reputation: 241
i assume you know how many days before was last sunday, in that case you can use this function
AddToDate(date, num_years, num_months, num_days)
it will return a date
example
AddToDate(Date(),0,0,-3)
, assuming sunday was 3 days before today
Upvotes: 1