Untitled
unknown
javascript
2 years ago
925 B
5
Indexable
// Input the birthdate from any layer, text, comp name etc. (mm, dd, yyyy) var birthDateUnfortmatted = thisComp.layer("Date of Birth").text.sourceText; // Get todays date var today = new Date(); //Split the input into its parts to rearrange later var birthDateParts = birthDateUnfortmatted.split(/[/]/); var month = birthDateParts[0]-1; var day = birthDateParts[1]; var year = birthDateParts[2]; // Format the birthdate (yyyy, mm, dd) var birthDate = new Date(year, month, day); // Subtract the birth year from todays years var age = today.getFullYear() - birthDate.getFullYear(); // Check if the month has already been reached/passed var m = today.getMonth() - birthDate.getMonth(); // Check if the birthday has already been reached/passed var d = today.getDate() - birthDate.getDate(); if(m == 0) if(d < 0) age -1; else age; else if (m < 0) age-1; else age;
Editor is loading...