Skip to content

Instantly share code, notes, and snippets.

@miller3818
Created July 28, 2014 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miller3818/218a0b3ff1ce42b1b9ae to your computer and use it in GitHub Desktop.
Save miller3818/218a0b3ff1ce42b1b9ae to your computer and use it in GitHub Desktop.
working with a csv date with an unknown number of characters
// working with a csv date with an unknown number of characters
// can be 7 characters if day is only 1 character long
// or it'll be 8 characters if day is 2 characters long
//var csvDate = "12231991";
function getDateFromString(csvDate) {
var myYear = 0;
var myMonth = 0;
var myDay = 0;
myYear = csvDate.slice(-4);
myMonth = csvDate.slice(-6, -4);
if (csvDate.length === 7) {
myDay = "0" + csvDate.slice(0,1);
} else {
myDay = csvDate.slice(0,2);
}
console.log(myYear);
console.log(myMonth);
console.log(myDay);
console.log(myDay + "/" + myMonth + "/" + myYear);
}
getDateFromString("2122009");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment