You need to sign in to do that
Don't have an account?
Rakesh M 20
Hi All, I am trying to exclude weekends in number of days in the month. This is what i have written for that, can anyone suggest how can i do that please ?
Integer Month = Date.Today().Month();
Integer Year = Date.Today().Year();
Integer numberDays = date.daysInMonth(Year, Month);
System.debug('Number of Days In Month--' +numberDays);
Date d = System.today();
Datetime dt = (DateTime)d;
String dayOfWeek = dt.format('EEEE');
Integer numberofdays;
for(Integer i=0;i<numberofdays;i++)
{
if(dayOfWeek=='Saturday' || dayOfWeek=='Sunday')
{
numberofdays=numberDays--;
System.debug('Number of Days After removing Weekends -- '+numberofdays);
}
}
Integer Year = Date.Today().Year();
Integer numberDays = date.daysInMonth(Year, Month);
System.debug('Number of Days In Month--' +numberDays);
Date d = System.today();
Datetime dt = (DateTime)d;
String dayOfWeek = dt.format('EEEE');
Integer numberofdays;
for(Integer i=0;i<numberofdays;i++)
{
if(dayOfWeek=='Saturday' || dayOfWeek=='Sunday')
{
numberofdays=numberDays--;
System.debug('Number of Days After removing Weekends -- '+numberofdays);
}
}
Greetings!
Please refer this thread and sample code provided below:
Kindly mark it as best answer if it helps so that it can help others in the future.
Warm Regards,
Shirisha Pathuri
Hi Rakesh,
Your for lopp would not work because intially there is nothhing in numberofdays.
Please find the solution I hope It will help You.
If It will help you please mark it best answer so that it can help others in the future.
Thanks