Skip to content

Instantly share code, notes, and snippets.

@gspncr
Created November 29, 2021 08:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gspncr/b4c644bca596efa31bcc5d23660ee593 to your computer and use it in GitHub Desktop.
Save gspncr/b4c644bca596efa31bcc5d23660ee593 to your computer and use it in GitHub Desktop.
Twilio Functions
// calculate the delta between the date you provide as an arg and the year of the current day.
// Provide it 01/01/2000 and you run this on 12/12/2020, this will return 20
exports.handler = function(context, event, callback) {
function formatDate(date){
var d = new Date(date), month = '' + (d.getMonth() + 1), day = '' + d.getDate(), year = d.getFullYear();
if (month.length < 2) month = '0' + month;
if (day.length < 2) day = '0' + day;
console.log(year)
return year
}
let birthDate = event.birthDate;
let thisYear = event.year;
console.log(event);
if (birthDate){
birthYear = formatDate(birthDate);
console.log(birthYear)
age = thisYear - birthYear;
return callback(null, age);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment