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
Kirtish ShrotriyaKirtish Shrotriya 

how to get month start date and end date for custom string date

I've a  string field conatins date  as 'month & year' example  '1 2018', '2 2018'.  I want to get month start date and moth end date for that custom string field. how can i archive that.?
Ayush TripathiAyush Tripathi
Ok so month start date will always be 1.
Then split the string and find the month from it and year in case of leap year condition for it
Convert the string to number by Integer.valueOf(string)
Then use the following code to find the end date.
 
Boolean isLeap = false;
if(month ==2){
if(year % 4 == 0)
        {
            if( year % 100 == 0)
            {
                if ( year % 400 == 0)
                    isLeap = true;
                else
                    isLeap = false;
            }
            else
                isLeap = true;
        }
        else {
            isLeap = false;
        }

        if(isLeap==true)
           endDate = 29;
        else
           endDate = 28;
    }
}
else if(month == 1 || month == 3 || month == 5 || month == 7 || month == 8 || month == 10 || month == 12){
endDate = 31;
}
else if(month == 4 ||month == 6 ||month == 9 ||month == 11 ){
endDate = 30;
}