0

I have an input type as text to select dates and I want that Its default value should be the earliest amongst the JSON data having following structure:

testData=
{
  "name":"ABC", transactions:[
  {"tranid":01,"trandate":"01/02/2010"},
  {"tranid":02,"trandate":"01/02/2012"}
  ]
}

I want to iterate through transactions and Dispay the earliest date in the text input(i.e 01/02/2010)

Please assist how to do it in angular.

3
  • mean you want the lowest date to be printed in the textfield Commented Jul 7, 2014 at 11:19
  • testData.transactions.trandate[0];
    – micronyks
    Commented Jul 7, 2014 at 11:19
  • I want to iterate throught the transactions data and find the lowest date and display it Commented Jul 7, 2014 at 11:23

2 Answers 2

0

Hi please see here: http://jsbin.com/reyog/1/edit

function finderliest()
  {    
        angular.forEach(testData.transactions, function(transaction){

       if($scope.erliest === undefined || transaction.trandate < $scope.erliest ){
             $scope.erliest = transaction.trandate;

      }
    });

  };
0
var len=testData.transactions.trandate.length;
if(len>0)
{
      for (i=0;i<len;i++)
     {
        for (j=1;j<len;j++)
        {
            var dateone=testData.transactions.trandate[i];
            var datetwo=testData.transactions.trandate[j];

            //(use this logic or else logic whichever you like) http://www.c-sharpcorner.com/UploadFile/8911c4/how-to-compare-two-dates-using-javascript/


        }
      }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.