function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
ramm12ramm12 

Need start date and End date

hi to all,

I have a retrieved week number from soql using aggregate result method.

For example January 10 menas it show WEEK 2.

I need to get start date and end date of the particular week 2


I dont want to use such as today function or date fields in formula or apex class.. I only need to get start date and end date using only the week number ?

Any help friends.......!
Ankit Gupta@ DeveloperAnkit Gupta@ Developer
Hi,

Try the below code snippet as reference:

string inputdate=system.today().format();
datetime startdate;
datetime enddate;
string startdatestring;
string enddatestring;

public void calculatedate(string inputdate)
{

    string inputdatformat=string.valueof(date.parse(inputdate));
    Datetime converttodatetime= datetime.valueOf(inputdatformat+' 00:00:00');
    String strConvertedDate = converttodatetime.format('EEEE/MM/yyyy');
    system.debug('################'+converttodatetime);
    system.debug(strConvertedDate);
    list<string> dayofcurrentday=strConvertedDate.split('/');
    string dayofweek=dayofcurrentday[0];
    integer i=1;
    startdate=converttodatetime;
     system.debug('################startdate'+startdate);
    while(dayofweek!='Monday')
    {

        datetime newDate = converttodatetime.addDays(-i);
        String strConvertedDate1 = newDate.format('EEEE/MM/yyyy');
        list<string> dayofcurrentday1=strConvertedDate1.split('/');
        system.debug(dayofcurrentday1);
        dayofweek=dayofcurrentday1[0];
        i=i+1;
        startdate=newDate;

    }
   enddate=startdate.adddays(6);
   startdatestring=startdate.format('dd/MM/yyyy');
  
   enddatestring=enddate.format('dd/MM/yyyy');
    system.debug('___startdatestring'+startdatestring+'____enddatestring'+enddatestring);

}

Ankit Gupta
Sure@DreamSure@Dream
Hi

try with DAY_IN_WEEK() function in soql..