Created
November 29, 2021 08:58
-
-
Save gspncr/b4c644bca596efa31bcc5d23660ee593 to your computer and use it in GitHub Desktop.
Twilio Functions
This file contains 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
// 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