'node js - MSSQL node module automatically converts Date as DateTime
I'm retrieving the SQL Date value from sql database using MSSQL node module through node js application but the resultant record set returns the date as Date time value.
2020-11-21 in database is displayed as 2020-11-21T00:00:00
Should we need to handle this explicitly?
Solution 1:[1]
This is not "DateTime", that's how toString of a Date object looks like in Javascript:
If you want it to be printed in a certain format that shows only the "date" portion, you can use toLocaleDateString():
const d = new Date()
console.log(d.toLocaleDateString()) // '11/18/2020'
or, if you want the result to be formatted like the example above: yyyy-mm-dd you can do:
d.toISOString().slice(0, 10); // '2020-11-18'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Nir Alfasi |

