Skip to main content
Hi All,

Can any one help me to calculate number of sunday's in a given month and year using apex and vf page.

Ex: If i select March 2017 from vf page, i need to calculate number of sunday's from selected month and year.

Thanks in advance.
3 件の回答
  1. 2019年9月17日 22:33
    Investigate the dayOfWeek method

     

    Integer month = 10;

    Integer year = 2019;

    Integer numberDays = Date.daysInMonth(year, month);

    Integer noOfSun = 0;

    for(Integer i=1;i<=numberDays ;i++)

    {

    Date myDate = date.newInstance(year, month, i);

    Datetime dt = (DateTime)myDate;

    if(dt.format('EEEE' == 'Sunday')

    {

    noOfSun = noOfSun + 1;

    }

    }

    Save the computations related to start date and modulos.

    Regards

    Andrew
0/9000