Created
July 28, 2014 18:36
-
-
Save miller3818/d376bf4dbbc5792a9231 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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 if (csvDate.length === 8) { | |
myDay = csvDate.slice(0,2); | |
} else { | |
return console.log("There is an error"); | |
} | |
console.log(myYear); | |
console.log(myMonth); | |
console.log(myDay); | |
console.log(myDay + "/" + myMonth + "/" + myYear); | |
} | |
getDateFromString("2101202"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment