-2
I’m pulling a date straight from Sqlserver, but this returning me in this format Apr 17 1995 12:00:000AM is possible to create a function that returns me this format 1995-17-04 with js?
-2
I’m pulling a date straight from Sqlserver, but this returning me in this format Apr 17 1995 12:00:000AM is possible to create a function that returns me this format 1995-17-04 with js?
1
Creates a function to format the date.
Handling dates in Javascript can be a bit boring, so you can do so:
function formatDate(sqlDate) {
var date = new Date(sqlDate.substring(0, 11)),
year = date.getFullYear(),
month = String(date.getMonth() + 1).padStart(2, '0'),
day = String(date.getDate()).padStart(2, '0');
return year + '-' + month + '-' + day;
}
Browser other questions tagged javascript
You are not signed in. Login or sign up in order to post.
Thank you very much Leonardo!
– Daniel Duarte