1

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.

sairam
  • 11
  • 5

3 Answers3

1

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

  • 1
    Well, the above function works if it is 3 days away from Sunday but I want the date to be previous Sunday everyday when I open the page. – sairam Jun 24 '15 at 21:14
  • 1
    Replace the -3 with the weekday(date()) * -1, if im not wrong sunday weekday is zero, im not in the office right now so i can't confirmed – Francisco Escobar Jun 24 '15 at 21:22
1

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

Ayesha Wee
  • 11
  • 2
-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)