You need to sign in to do that
Don't have an account?

how do i display the current week dates?
Hi,
I am trying to display dates of current week. How can i do it? What i am trying to do is display the timesheet for the week.
So if i view the page today then it should display me the current week dates. Any pointers to approach this problem would be very helpful
Thanks
Prady
Find below a sample code to get the week of month :
public Integer currentWeekOfMonth( Date todaysDate){
Date currentDate = todaysDate;
Integer weekCount = 0;
Integer startWeekResidue = 0;
Integer endWeekResidue = 0;
/*
Calculating startWeekResidue
*/
Date dt = currentDate.toStartOfMonth().addDays(-1);
Date dtFirstWeekend = dt.toStartOfWeek().addDays(6);
startWeekResidue = dt.daysBetween(dtFirstWeekend);
/*
Calculating endWeekResidue
*/
Date dtLastWeekend = currentDate.toStartOfWeek().addDays(-1);
endWeekResidue = dtLastWeekend.daysBetween(currentDate);
/*
Counting the weeks
*/
weekCount = (currentDate.day() - (startWeekResidue + endWeekResidue))/7;
weekCount += (startWeekResidue > 0 ? 1:0)+(endWeekResidue > 0 ? 1:0);
System.debug(weekCount);
return weekCount;
}
All Answers
Hi,
Can you post your code?
Thanks.
Hi prady,
I'd start with an Apex method that outputs a List collection of Dates making use of System.Today() and the toStartOfWeek() instance method to figure out the start of the week (depending on locale) then looping to build up the 7 dates for that week.
You could then iterate over that collection in the VF page with an apex:repeat tag, although depending on how you're wanting to display them (i.e., dates are more often repeated horizontally than vertically) you'll need to do some clever stuff with CSS (I've used float in the past to achieve this kind of effect).
Hope that helps.
Manu
Find below a sample code to get the week of month :
public Integer currentWeekOfMonth( Date todaysDate){
Date currentDate = todaysDate;
Integer weekCount = 0;
Integer startWeekResidue = 0;
Integer endWeekResidue = 0;
/*
Calculating startWeekResidue
*/
Date dt = currentDate.toStartOfMonth().addDays(-1);
Date dtFirstWeekend = dt.toStartOfWeek().addDays(6);
startWeekResidue = dt.daysBetween(dtFirstWeekend);
/*
Calculating endWeekResidue
*/
Date dtLastWeekend = currentDate.toStartOfWeek().addDays(-1);
endWeekResidue = dtLastWeekend.daysBetween(currentDate);
/*
Counting the weeks
*/
weekCount = (currentDate.day() - (startWeekResidue + endWeekResidue))/7;
weekCount += (startWeekResidue > 0 ? 1:0)+(endWeekResidue > 0 ? 1:0);
System.debug(weekCount);
return weekCount;
}
Thanks a lot...
This is more than what i had asked for.. I just needed some pointers on how to go about doing it.. Pradeep just gave me the code...
Thanks for all the help..
Regards
Prady