Before applying any string functions to the date object we must convert it to string by using toString function.
Date.toString();
Sample code
<script type="text/javascript">
var dt= new Date();
document.write(dt + "<br><br>");
document.write(dt.toString());
</script>
The output is here
After conversion to string we can apply any string function like this .
document.write(dt.toString().substr(5));
Difference between toDateString() and toString()
toDateString(): Returns only the date part of a Date object in a human-readable format (e.g., "Mon Sep 06 2021"). It excludes the time and timezone information.
toString(): Returns a full string representation of the Date object, including the day, date, time, and timezone (e.g., "Mon Sep 06 2021 14:20:30 GMT+0000 (UTC)").
let date = new Date();
console.log(date.toDateString()); // "Mon Sep 06 2021"
console.log(date.toString()); // "Mon Sep 06 2021 14:20:30 GMT+0000 (UTC)"