I have a simple problem. i need to get only the date as string and remove its time. How can i do this? I tried new Date() but its not working.
const value = '2018-04-09 00:00:00'
I have a simple problem. i need to get only the date as string and remove its time. How can i do this? I tried new Date() but its not working.
const value = '2018-04-09 00:00:00'
 
    
    You can try this
const currentDate = new Date();
const formattedDate = ''
  + currentDate.getDate().toString().padStart(2, '0') + '-'
  + (currentDate.getMonth() + 1).toString().padStart(2, '0') + '-'
  + currentDate.getFullYear();
console.log(formattedDate)
// output
"09-05-2019"
 
    
    function yyyymmdd(date) {
  var mm = date.getMonth() + 1; // getMonth() is zero-based
  var dd = date.getDate();
  return [date.getFullYear(),
          (mm>9 ? '' : '0') + mm,
          (dd>9 ? '' : '0') + dd
         ].join('-');
};
let date=new Date()
console.log(yyyymmdd(date))