Skip to content

Instantly share code, notes, and snippets.

@maartenpaauw
Created July 16, 2015 10:27
Show Gist options
  • Save maartenpaauw/65d82a8fdf81802c60fd to your computer and use it in GitHub Desktop.
Save maartenpaauw/65d82a8fdf81802c60fd to your computer and use it in GitHub Desktop.
Parse the IFTTT date to dd-mm-yyyy hh:mm:00
function IFTTT_DATE(str){
var time = str.split(" "), months, timestring, parsed_hour,
year, month, day, hour, minute, output;
months = {
"Jan": "01", "January": "01",
"Feb": "02", "February": "02",
"Mar": "03", "March": "03",
"Apr": "04", "April": "04",
"May": "05",
"Jun": "06", "June": "06",
"Jul": "07", "July": "07",
"Aug": "08", "August": "08",
"Sep": "09", "Sept": "09", "September": "09",
"Oct": "10", "October": "10",
"Nov": "11", "November": "11",
"Dec": "12", "December": "12"
};
year = time[2];
month = months[time[0]];
day = time[1].replace(",","");
timestring = time[4].split(":");
parsed_hour = (+timestring[0]).toFixed(0);
if (time[4].indexOf("PM") > -1 && parsed_hour < 12) {
hour = +parsed_hour + 12;
} else {
hour = parsed_hour;
if(hour <= 9) {
hour = "0" + hour;
}
}
minute = timestring[1].substring(0, timestring[1].length - 2);
output = day + "-" + month + "-" + year + " " + hour + ":" + minute + ":00";
return output;
}
@oscarmorrison
Copy link

Does this work in Google Scripts for SpreadSheet?

@maartenpaauw
Copy link
Author

@oscarmorrison a bit late, but this works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment