Created
July 28, 2014 16:42
-
-
Save miller3818/218a0b3ff1ce42b1b9ae to your computer and use it in GitHub Desktop.
working with a csv date with an unknown number of characters
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 { | |
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