Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript yyyy-mm-dd to mm-dd-yyyy human readable format

function formatDate(DB_date){
  // Get Date from DB then format it to be human readable
// DB_date comes in as yyyy-mm-dd which throws off the date format by one day
 var ymdSplit = DB_date.split('-');
 // so we split it into an array and then we can use the array to create a new date object
// console.log(ymdSplit[0])
// console.log(ymdSplit[1])
// console.log(ymdSplit[2])
 var d = new Date(""+ymdSplit[1]+"/"+ymdSplit[2]+"/"+ymdSplit[0]+"");
// re-assembles the date object into a string
// console.log(d)
var wd = d.getDay();
var mo = d.getMonth();
let weekdays = ["Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"];
let months = ["January","February","March","April","May","June","July","August","September","October","November","December"];
// console.log(weekdays[wd])
// console.log(months[mo])
  // return this function so it comes back as: Tuesday, March 15th, 2022 :) all done!
return weekdays[wd] + ", " + months[mo] + " " + ymdSplit[2] + ", " + ymdSplit[0];
}
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #javascript #human #readable #format
ADD COMMENT
Topic
Name
2+3 =