function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rafat89778Rafat89778 

Age Calculate from Date In LWC

I am trying to built a age calculator. calculator take input from calendar and output age. but this program don't show anything.

Agecalculator.html
<template>
    <lightning-card  title="Age Calculator">
        <lightning-button variant="brand" label="Calculate"  slot="actions" onclick={calculateDOB}></lightning-button>
        <p class="slds-p-horizontal_small">
            <lightning-input type="date" name="BirthDate" label="Enter Your Date Of Birth" placeholder="type here..." value={birthdate} onchange= {handleChangeNum1}></lightning-input>
            result---{result}
        </p>
    </lightning-card>
</template>
AgeCalculator.js
export default class AgeCalculator extends LightningElement {
    @track result;
    @track birthdate;
    today = new Date();


    handleChangeNum1(event){
        const inpurdate = event.target.name;
        const inputvalue= event.target.value;
        if(inpurdate=='BirthDate'){
            this.birthdate=inputvalue;
        }

    }
    calculateDOB (event) {

        this.result=today.getfullyear-this.birthdate.getfullyear;
    }
}


 
SwethaSwetha (Salesforce Developers) 
HI Yeasir ,
I see you also posted on https://salesforce.stackexchange.com/questions/340010/age-calculate-from-date-in-lwc . Can you try the suggestion listed as comment and let me know how it goes?

"JavaScript is case sensitive and () is needed to invoke a function. Use your browser's Developer Console to see JavaScript errors."
Malika Pathak 9Malika Pathak 9
Hi Yeasir Arafat,
 
First i Want to that you will able to your lwc Component or not 
if not may be your meta xml file configuration is not set
 for that you can refer my xml file code  given below 
 <?xml version="1.0" encoding="UTF-8"?>

<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">

<apiVersion>51.0</apiVersion>

<isExposed>true</isExposed>


<targets>

<target>lightning__AppPage</target>

<target>lightning__RecordPage</target>

<target>lightning__HomePage</target>

<target>lightningCommunity__Page</target>

</targets>

</LightningComponentBundle>

if your component not work after that or your configuration is already set than reply me i will check for you again

if you find your Solution than mark as best answer as well 
thanks and Regards
Malika Pathak.
Rafat89778Rafat89778
hi Swetha 
JavaScript error is solved but i have other problems. output value is showing NaN
Vinay MVinay M

Hi Yasir,

 

   getFullYear is a method in Javascript which works on Date object. So please try 

   this.result = this.today.getFullYear() - this.birthdate.getFullYear();

 

Thank you,

Vinay.