-3

Here I want to format billDetail.invoiceDate as dd-mm

my code is

$.each(data.billDetails, function(position, billDetail) {

      if (billDetail.invoiceDate) {
             //I tried
             var dat = (billDetail.invoiceDate).format("dd-mm");//Showing  error
             chartData.labels.push(dat); 
      } else {

        chartData.labels.push(''); 
      }

      chartData.datasets[0].data.push(billDetail.totalBills);
      chartData.datasets[1].data.push(billDetail.totalAmount);
    });

Showing error

    Uncaught TypeError: undefined is not a functiondashboard.action:221
 (anonymous function)jquery-2.1.1.min.js:2 n.extend.eachdashboard.action:218 
 $.ajax.successjquery-2.1.1.min.js:2 jjquery-2.1.1.min.js:2 k.fireWithjquery-2.1.1.min.js:4 
   xjquery-2.1.1.min.js:4 (anonymous function)

My data as given in console is

dashboard.action:191 2014-11-25T00:00:00 4 1545
dashboard.action:191 2014-11-24T00:00:00 6 24497
dashboard.action:191 2014-11-23T00:00:00 1 114
dashboard.action:191 2014-11-22T00:00:00 1 114
dashboard.action:191 2014-11-18T00:00:00 5 4916
dashboard.action:191 2014-11-13T00:00:00 7 29040
dashboard.action:191 2014-11-01T00:00:00 4 7317
dashboard.action:191 2014-10-31T00:00:00 7 53061
dashboard.action:191 2014-10-30T00:00:00 1 114
xrcwrn
  • 4,867
  • 17
  • 58
  • 117

1 Answers1

1

Just use the getDate() and getMonth() Date Object Methods :

Your billDetail.invoiceDate is a String so make it a Date then manage it.

var d = new Date(billDetail.invoiceDate);
var dat = d.getDate()+"-"+parseInt(d.getMonth()+1);

This is the working fiddle.

That should do it.

cнŝdk
  • 28,676
  • 7
  • 47
  • 67