I am trying to convert a JSON string date (in Google Apps Script) to JavaScript date object and then check to see if that date is after another date but I can't get it to work.
I tried using the suggestion here. but my output is incorrect. What am I doing wrong? Thanks for your help.
Code Snippet:
var json = JSON.parse(resp);
var flightDate = new Date(json[i].flightDate)
for (i = 0; i < json.length; i++ {
flightDate = json[i].flightDate
traveler = json[i].traveler
flight = json[i].flight
destination = json[i].destination
var afterDate = new Date('1997-07-30')
if (flightDate >= afterDate) {
output.push ([flightDate, traveler, flight, destination])
}
}
Output:
1969-12-31
JSON:
[{"flightDate": "2013-03-01",
"traveler": "Paul Carter",
"flight": "JetBlue",
"destination": "Australia"
},
{"flightDate": "1997-02-18",
"traveler": "Paul Carter",
"flight": "American Airlines",
"destination": "Australia"
},
{"flightDate": "2004-05-25",
"traveler": "Paul Carter",
"flight": "JetBlue",
"destination": "Chile"
},
{"flightDate": "1995-08-05",
"traveler": "Paul Carter",
"flight": "United",
"destination": "Ireland"
}]
UPDATE:
JSON in this question was updated to accurately reflect what I have on my computer so the issue isn't the JSON formatting. I'm mainly interested in converting the JSON string date to JavaScript date. Please note that since this is in Google Apps Script, importing libraries (i.e. Moment.js) is not possible.