Calculate current year birthday based off birthday field
Hi guys - needing to make a calculation to show the birthday of the current year based off the date we key in for the birthday. Example. If a the Date of Birth field is 01/01/1980 this as of today (4/16/18) I need the calculated field to be 01/01/2019. Likewise if the birthday is 06/01/1980, the calculated field would be 06/01/2018.
Struggling a little with this using moment.js. Having a hard time extracting the year and attaching the next birthday. Do not want to use current year as the variable if it can be helped.
Thanks!
-
I think I got it. Had to extract year, month and date separately. Then get the current date. Use If statement to check if current month is greater than birth month, if so set birthdate to next year, else set it to this year.// Get Date of Birth Entry
var dOb = @DOB;
// Extract Birth Month
var birthMonth = dOb.getMonth();
// Extract Birth Date
var birthDate = dOb.getDate();
// Extract Birth Year
var birthYear = dOb.getFullYear();
// Get Today's Date
var today = new Date();
// Get Today's Month
var curMonth = today.getMonth();
// Get Today's Year
var curYear = today.getFullYear();
// Get This Year's Birthday
var curYearBirthday = new Date(curYear, birthMonth, birthDate);
// Get Next Year's Birthday
var nextYearBirthday = new Date(curYear +1, birthMonth, birthDate);// If the current month is bigger than than the birth month set this date to the birthday of next yearif (curMonth > birthMonth)
nextYearBirthday;// Else, set the birthday to this year's birthday
elsecurYearBirthday -
Hi Nathan,
sorry to disappoint you: But var today = new Date(); doesn't work. You'll get the date of the day you save the template (or a new item) - next year you'll have the same 2018 date.
More about this issue: https://help.podio.com/hc/en-us/community/posts/204569657-Definite-solution-for-today-handling-in-calculated-fields-days-since-days-until-countdown-incl-possible-solutionRainer
Please sign in to leave a comment.
Comments
6 comments