Skip to main content

Notifications

Community site session details

Community site session details

Session Id :
Power Pages - Customize & Extend
Unanswered

Javascript - calculate age from date field - power pages

(0) ShareShare
ReportReport
Posted on by 623

what am I  doing wrong

 

ctedesco3307_0-1696346693574.png

 

  • Lucas001 Profile Picture
    2,174 Super User 2025 Season 1 on at
    Re: Javascript - calculate age from date field - power pages

    Hi @ctedesco3307,

     

    the problem you face is that the .val() returns a string which you need to change into a date.

    The following code works as expected.

     

    dob = Date.parse('5/30/2000');
    var today = new Date();
    var age = Math.floor((today-dob) / (365.25 * 24 * 60 * 60 * 1000));
    
    console.log(age);
    // Expected output: 23

     

     

    One thing you have to take care is the timezone. In case it's a global application you will have the date as you currently do in dd/mm/yyyy but probably some others in mm/dd/yyyy

     



    --------------------------------------------------------------------------------------

    Hope that helps.

    If the post solves your problem, please mark it as solution. If it helps, consider a thumbs up.

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Michael Gernaey – Community Spotlight

We are honored to recognize Michael Gernaey as our June 2025 Community…

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard >

Featured topics