the timestamp I receive from Api is something like 2018-02-24T00:00:00 , but what I need is MM/DD/YYYY so.. it would look something like 02/24/2018, I receive timestamp from mssql and want to convert it using javascript
Converting the sql date to MM/DD/YYYY
229 Views Asked by shank511 At
2
There are 2 best solutions below
0

You can try:
function getFormattedDate(date) {
let year = date.getFullYear();
let month = (1 + date.getMonth()).toString().padStart(2, '0');
let day = date.getDate().toString().padStart(2, '0');
return `${month}/${day}/${year}`;
}
function getFormattedDate(date) {
let year = date.getFullYear();
let month = (1 + date.getMonth()).toString().padStart(2, '0');
let day = date.getDate().toString().padStart(2, '0');
return `${month}/${day}/${year}`;
}
console.log(getFormattedDate(new Date('2018-02-24T00:00:00')))
or as US culture