I am running into a problem I'm trying to understand. I am simply trying to convert a date into a more reader-friendly format by using toDateString(). However, in doing so I am getting a "toDateString() is not a function" error.
I can do this, using toString():
truncateDate() {
if (this.employee && this.employee.dob)
{
let birthDate = this.employee.dob;
console.log(birthDate); // 2011-06-12T05:00:00.000Z Prints to console
console.log(birthDate.toString());
}
}
But I cannot do toDateString():
truncateDate() {
if (this.employee && this.employee.dob)
{
let birthDate = this.employee.dob;
console.log(birthDate); // 2011-06-12T05:00:00.000Z Prints to console
console.log(birthDate.toDateString());
}
}
What am I missing here?
Convert the string to Date Object then you will be able to use that function. Here is MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/toDateString
this.employee={}
this.employee.dob='1/2/2018'
let birthDate = this.employee.dob;
console.log(birthDate);
console.log(new Date(birthDate).toDateString());
//
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With