Date Time Replacement In IFTTT with google script

in spreadsheet •  7 years ago 

IFTTT is good macro tool.
But OccuredAt format is not compatible with google datetime.

=TIMEVALUE(SUBSTITUTE("{{OccurredAt}}"," at ", " ")) + DATEVALUE(SUBSTITUTE("{{OccurredAt}}"," at ", " "))
Above is not working.

So, I write new custom function.

function dtr(myDate){
var vv = myDate;

vv = vv.toString();

var va = vv.split(" at ");
if(va[1]==undefined){
return;
}
var ampm = va[1].split(":");

if(va[1].substr(-2)=="PM"){
myDate = new Date((va[0].replace(",","")+", "+(parseInt(ampm[0],10)+12)+":"+ampm[1].substr(0,2)+":00"));
}else{
myDate = new Date((va[0].replace(",","")+", "+parseInt(ampm[0],10)+":"+ampm[1].substr(0,2)+":00"));
}
return myDate;
}

s1.jpg

Create new script in spreadsheet.

s2.jpg

Save script.

And you edit your IFTTT

=dtr("{{OccurredAt}}")

s3.jpg

Check your Logs!

s4.jpg

Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!