Skip to main content
Narendra Reddy Gopavaram (Acteion) a posé une question dans #Apex
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 réponses
  1. 17 sept. 2019, 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