JavaScript How to print only Day instead of full date?

I have full Date in my JSON Array,but as of my needs i only want the date not the month and year like if full date is 2018-12-01 i want to have only 01.

As this is the requirement for me and i have no idea how can i concatenate this

const raw = [
  [
    "JAYANAGAR",
    "2018-09-01",
    "476426"
  ],
  [
    "MALLESHWARAM",
    "2018-09-01",
    "92141"
  ],
  [
    "KOLAR",
    "2018-09-01",
    "115313"
  ],
  [
    "JAYANAGAR",
    "2018-09-02",
    "511153"
  ],
  [
    "MALLESHWARAM",
    "2018-09-02",
    "115704"
  ],
  [
    "KOLAR",
    "2018-09-02",
    "83597"
  ],
  [
    "JAYANAGAR",
    "2018-09-03",
    "167421"
  ],
  [
    "KOLAR",
    "2018-09-03",
    "53775"
  ]
]
let types = new Set();
const rawObj = raw.reduce((memo, [type, date, value]) => {
  date = date.split('-').reverse().join('-');
  memo[date] = memo[date] || {};
  memo[date][type] = parseInt(value);
  types.add(type);
  return memo;
}, {});
types = [...types];

const data = Object.entries(rawObj).reduce((memo, [date, value]) => {
  memo.push([date, ...types.map(type => value[type] || 0)]);
  return memo;
}, [
  ['Billdate', ...types.map(type => `${type[0]}${type.substr(1).toLowerCase()}`)]
]);

console.log(data)
Answer:1
var date = new Date('2019-01-02');
alert(date.getDate())

.getDate() is the function which returns the day from a date.

If the date is string do-

console.log(date.slice(-2));
Answer:2

You can first convert tour date string to Date Object and then use getDate() to get the date. This would guarantee support for various date-time format.

var date = new Date('2018-09-01')
console.log(date.getDate());
Answer:3

You can change the date string to Date object and use the getDate function to get the date part

var d = new Date('2018-09-03');
console.log(d.getDate())
Answer:4

Try adding this:

new Date("2018-09-03").getDate();
Answer:5

I will tell you to get your raw array in desired form in the first statement itself as follows.

Note: Then you move forward with you logic after that. Creating new dates using new Date() statement doesn't make sense.

const raw = [
   [
     "JAYANAGAR",
     "2018-09-01",
     "476426"
   ],
   [
     "MALLESHWARAM",
     "2018-09-01",
     "92141"
   ],
   [
     "KOLAR",
     "2018-09-01",
     "115313"
   ],
   [
     "JAYANAGAR",
     "2018-09-02",
     "511153"
   ],
   [
     "MALLESHWARAM",
     "2018-09-02",
     "115704"
   ],
   [
     "KOLAR",
     "2018-09-02",
     "83597"
   ],
   [
     "JAYANAGAR",
     "2018-09-03",
     "167421"
   ],
   [
     "KOLAR",
     "2018-09-03",
     "53775"
   ]
 ].map((l) => { l[1] = l[1].split('-')[2]; return l})

console.log(raw)
/*
  [ [ 'JAYANAGAR', '01', '476426' ],
    [ 'MALLESHWARAM', '01', '92141' ],
    [ 'KOLAR', '01', '115313' ],
    [ 'JAYANAGAR', '02', '511153' ],
    [ 'MALLESHWARAM', '02', '115704' ],
    [ 'KOLAR', '02', '83597' ],
    [ 'JAYANAGAR', '03', '167421' ],
    [ 'KOLAR', '03', '53775' ] ]
*/
Answer:6

Try This code

var weekday = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
var d = new Date('08/11/2015');
alert(weekday[d.getDay()]);
Answer:7

You can use moment.js which is simple to use:

<script src="https://momentjs.com/downloads/moment.js"/>

var day = moment(new Date('2018-09-03')).format('DD');
Answer:8

How to get output HTML and CSS of grapes.js in Javascript ? I am writing a Django app for newsletter, in which I need a newsletter editor for which I used "grapes.js" newsletter. Everything is fine ...

How to get output HTML and CSS of grapes.js in Javascript ? I am writing a Django app for newsletter, in which I need a newsletter editor for which I used "grapes.js" newsletter. Everything is fine ...

In Angularjs, I keep lot of data in my services so that the server calls can be reduced and the data can be picked from local variables. This leads to data being persisted in the application till user ...

In Angularjs, I keep lot of data in my services so that the server calls can be reduced and the data can be picked from local variables. This leads to data being persisted in the application till user ...

I've just learnt about Getters/Setters for objects and decided to play with it. However, I tried to put a Getter in an array and failed to do so. Is it not possible or am I just doing something wrong? ...

I've just learnt about Getters/Setters for objects and decided to play with it. However, I tried to put a Getter in an array and failed to do so. Is it not possible or am I just doing something wrong? ...

I have a fairly simple webpack set up with a bit of a twist. I have a few different ways I can think of to create my intended behavior, but I'm wondering if there are better approaches (I'm still ...

I have a fairly simple webpack set up with a bit of a twist. I have a few different ways I can think of to create my intended behavior, but I'm wondering if there are better approaches (I'm still ...

  1. vue manually trigger watch
  2. angularjs manually trigger watch