String  dateSplit = '2015/05/05'
 List<String> arr = new List<String>();
 arr = dateSplit.split('/');

 String tempDate = '';
 for(Integer i=arr.Size();i>=0;i--){
    if(tempDate == ''){
        tempDate = arr[i];
        tempDate = tempDate + '/' + arr[i];
 Date depDate = Date.parse(tempDate);

1 Answer 1


akash, is this code just for your learning ? why do you use hard coded dates and convert the format and parse it ?

Date.parse usually parses the string into date using user's locale date format.

so no point in changing the format to pass it to parse method.

now to the error you are getting,

  • its becos you are starting the loop from arr.size() which is always 1 plus index of the last element stored in the array (since arrays starts storing element from 0 index)
  • so start your looping from arr.size()-1 and you should be good

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .