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

Notifications

Announcements

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 690

what am I  doing wrong

 

ctedesco3307_0-1696346693574.png

 

Categories:
I have the same question (0)
  • Lucas001 Profile Picture
    2,429 Super User 2025 Season 2 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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Pages

#1
Jerry-IN Profile Picture

Jerry-IN 71

#2
Fubar Profile Picture

Fubar 62 Super User 2025 Season 2

#3
sannavajjala87 Profile Picture

sannavajjala87 31

Last 30 days Overall leaderboard