how to set the current date field to previous Sunday in peoplesoft - peoplesoft

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.

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

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

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)

Related

How to set start of the week as Sunday and end as Saturday in Dart?

I can get start of the week as Monday using method below:
DateTime findFirstDateOfTheWeek(DateTime date) {
return date.subtract(Duration(days: date.weekday - 1));
}
and end of the week, the Sunday, as:
DateTime findLastDateOfTheWeek(DateTime date) {
return date.add(Duration(days: DateTime.daysPerWeek - date.weekday));
}
Now the requirements are, to treat Sunday as week start and Saturday as week end. I tried tweaking above method but could not get it working. Any help would be appreciated.
Thanks
Since DateTime.weekday counts from 1 (Monday) to 7 (Sunday):
date.subtract(Duration(days: date.weekday - 1))
will give us the date of the start of the week using what DateTime considers to be the first day of the week (Monday). To treat Sunday as the first day of the week instead, we can try to get the previous day from that:
date.subtract(Duration(days: date.weekday - 1)).subtract(const Duration(days: 1))
The above is algebraically equivalent to date - (weekday - 1) - 1, which can be simplified to just date - weekday. But that's not quite right because weekday ranges from [1, 7], and we never want to subtract 7 days. In that case, we want to subtract 0. The modulus operator handles that nicely, ultimately giving us:
DateTime findFirstDateOfTheWeek(DateTime date) {
return date.subtract(Duration(days: date.weekday % DateTime.daysPerWeek));
}
To get the last day of the week where Saturday is treated as the last day of the week, you can just get the first day of the week and add 6 days:
DateTime findLastDateOfTheWeek(DateTime date) {
return findFirstDateOfTheWeek(date).add(
const Duration(days: DateTime.daysPerWeek - 1));
}

I inserted rows with the UTC date into an int column in my database. How can I get just the rows that were inserted in the last 24 hours?

Here's the insert that I used:
db2.Insert(new QuizHistory()
{
QuizId = quiz,
Cards = 0,
Points = points,
UtcNow = (int)Math.Truncate(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1)).TotalSeconds),
Viewed = 1,
Deck = deck
});
I tried looking at the different sql functions but now I am more confused than ever.
select * QuizHistory << but just for the last 24 hours.
As you are storing the date as seconds since january 1, 1970, a solution would be to use strftime :
select *
from QuizHistory
where UtcNow > strftime('%s', 'now', '-1 day')
i.e. with %s as format (seconds since 1970-01-01), for the now date with a -1 day modifier

Given a date how to get Sunday & Saturday of that week

I want to get the Sunday & Saturday of the week from which a date is provided.
I have access to the following functions only:
getDate() returns a number from 0-6 (0 being sunday)
getDay() returns a number from 1-31
getMonth() returns a number from 0-11
getFullYear() returns the current year
I am doing this on titanium.
Per your description above, I came up with:
var sat = new Date(input.getFullYear(), input.getMonth(), 6 - input.getDate() + getDay());
var sun = new Date(input.getFullYear(), input.getMonth(), getDay() + (input.getDate() - 6));
If I follow the MDN doc, I come up with (works in Ti too):
var sat = new Date(input.getFullYear(), input.getMonth(), 6 - input.getDay() + input.getDate());
var sun = new Date(input.getFullYear(), input.getMonth(), input.getDate() + (input.getDay() - 6));
Where input is a javascript Date object.
The date object will take care or changing the month and/or year if necessary.
Hope this helps.

Find This Weeks Monday

How do I get the date of this current week's Monday. Where Monday is the first day of the week. So if I was to look up this weeks it would return the date 1/16/2012
I am using VBScript and ASP
Many thanks in advance..
Paul
Effectively, the Weekday function returns Sunday=1, Monday=2, etc. To get the Monday of the same week, you want to subtract:
Sunday (1): 6 days
Monday (2): 0 days
Tuesday(3): 1 day
...
Saturday(7): 5 days.
Or
Days to subtract = (Weekday - 2 + 7) Mod 7
So if d is a date, the Monday of the same week can be written as:
mondayofsameweek = DateAdd("d", -((Weekday(d) + 7 - 2) Mod 7), d)
VBScript has a function called WeekDay, it return 1 - 7, not sure whether 1 is Monday though, usually you can twiddle with that.
Either way get the weekday Thursday = 4? , so then you just need to take three days off your date with thae DateAdd function
In VBScript WeekDay returns the day of the week, starting with Sunday=1 (VBScript can be quirky like that). So just subtract two (Monday=2) from that value and call DateAdd.
monday = DateAdd("d",(WeekDay(Date())-2),Date())
I know the topic is a bit old, but I figured I'd share my working solution that I think is a bit more concise.
Where dDate is your current date:
dDate = DateAdd("d", -(WeekDay(dDate, vbMonday) - 1), dDate)
The second parameters of WeekDay is the day you want the week to 'start'. For me, in the US, WeekDay corresponds the default second parameter to vbSunday. Specifying vbMonday, we just get the difference (base 1) between our current weekday and Monday.
Subtract 1 and add the inverse to your current date should obtain your result.
Example:
WeekDay(2018-03-20, vbMonday) = -((2) - 1) = DateAdd("d", -1, 2018-03-20)

Flex: How to get the number of Days in a particular month in Flex?

I am having a problem with flex.
How can I get the number of Days in a particular month in Flex?
Thanks
Use the Date object , setting the day to 0, getDate will return the last day in the month which is also the day count; you have also to give the year you want to check, because you know february can have 29 days.
function getDayCount(year:int, month:int):int{
var d:Date=new Date(year, month, 0);
return d.getDate();
}
trace(getDayCount(2012,2));
The example above doesn't work for January!
new Date(2011,0,0) returns 12/31/2010
new Date(2011, 1, 0) returns 01/31/2011
new Date(2011, 1, 1) returns 02/01/2011
Create a new date object by specifying the year, desired month + 1, and a day of 0. This will create a date object for the last day of the desired month. Then call getDate() on the object to return the last day.
Note that months are zero based in Flex, so Jan = 0, Feb = 1, and so on. Therefore, if you want to know what the last day in Feb was for 2012 you would do the following:
var FEB:int = 1;
var date:Date = new Date(2012, FEB + 1, 0);
var lastDayInFeb:Number = date.getDate();
Here is a more complete example with a couple of non-unit tests and a reusable static method for returning the last day of a month.

Resources