• Resolved aabdurraahim

    (@aabdurraahim)


    Trying to build an age calculation. I want to show “Abdur Rahim is 25 years old now in October 2023. To be more specific, he is 25 years, 7 months, & 0 days old today, and his next birthday is in 5 months and 0 days from today.”

    So far I have built, “Abdur Rahim is 25 years old now at [need the current month and year here]. To be more specific, he is 25 years, 7 months, & 0 days old today. [need to subtract from the next birth date and get how many months or day remains.]”

    My codes so far.
    Age Calculation:

    (function(){
    var o = DATEDIFF(NOW(), fieldname1, ‘dd-mm-yyyy’, ‘y’);
    return o[‘years’]+’ years old ‘;
    jQuery(‘#calculation-yashesaplama’).html(yashesaplama);
    return yashesaplama;
    })()

    Age, Month, Dates Calculation:

    (function(){
    var o = DATEDIFF(NOW(), fieldname1, ‘dd-mm-yyyy’, ‘y’);
    return o[‘years’]+’ years, ‘+ o[‘months’]+’ months, & ‘+ o[‘days’]+’ days old’;
    jQuery(‘#calculation-yashesaplama’).html(yashesaplama);
    return yashesaplama;
    })()

    Output with summary field: <p><b>Abdur Rahim</b> is  <b data-cff-field="fieldname3"></b> now at <span data-cff-field="fieldname6"></span>. To be more specific, he is <b data-cff-field="fieldname4"></b> today.</p>

    screenshot of how it is now.

    So can you help me, how can I get the current year? and is it possible to subtract the remaining months and days for the next birthday? if it is, how?

    asked a lot of questions. sorry for troubling you. I appreciate your effort. thanks.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @aabdurraahim

    You only need to determine the next birthday.

    For example, if fieldname1 contains the user’s birthday, the next birthday can be determined as follows:

    (function(){
    var t = TODAY(), 
    m = MONTH(fieldname1), 
    d = DAY(fieldname1), 
    y = SUM(YEAR(t), IF( OR( m<MONTH(t), AND( m == MONTH(t), d<= DAY(t))), 0, 1 )),
    
    o = DATEDIFF(d+'-'+m+'-'+y, TODAY(), 'dd-mm-yyyy', 'm');
    
    return 'Time to the next birthday '+o['months']+' months and '+o['days']+' days';
    })()

    Best regards.

    Thread Starter aabdurraahim

    (@aabdurraahim)

    (function(){
    var t = TODAY(), 
    m = MONTH(fieldname1), 
    d = DAY(fieldname1), 
    y = SUM(YEAR(t) + 1, IF( OR( m<MONTH(t), AND( m == MONTH(t), d<= DAY(t))), 0, 1 )),
    
    o = DATEDIFF(d+'-'+m+'-'+y, TODAY(), 'dd-mm-yyyy', 'm');
    
    return 'Time to the next birthday '+o['months']+' months and '+o['days']+' days';
    })()

    Working, Thanks

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Age Calculator’ is closed to new replies.