web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Pages / Javascript - calculate...
Power Pages
Unanswered

Javascript - calculate age from date field - power pages

(0) ShareShare
ReportReport
Posted on by 857

what am I  doing wrong

 

ctedesco3307_0-1696346693574.png

 

Categories:
I have the same question (0)
  • Lucas001 Profile Picture
    2,562 Super User 2026 Season 1 on at

    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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Pages

#1
11manish Profile Picture

11manish 52

#2
Valantis Profile Picture

Valantis 46

#3
Vish WR Profile Picture

Vish WR 29

Last 30 days Overall leaderboard