Activity Forums Salesforce® Discussions get Year only from input field type="date" in lightning component controller

  • get Year only from input field type="date" in lightning component controller

    Posted by Akash on January 1, 2021 at 10:02 am

    hi,

    can we get only year value from input whose type is DATE in controller.js
    like
    <lightning:input type="Date" label="DOB" value="{!v.CustomerRecord.DOB__c}" required="true" aura:id="DOB" />

    var date=component.find('DOB').get('v.value');
    i want to do age comparison ,plz provide any proper solution..

    Akash replied 3 years, 10 months ago 2 Members · 2 Replies
  • 2 Replies
  • Anjali

    Member
    January 4, 2021 at 12:54 pm
  • Akash

    Member
    January 4, 2021 at 4:32 pm

    Thanks Anjali...for the reference link.

    but i need to get only year value of input date type field so that i use it for comparison purpose and got that solution..

    from input field i taken value using aura:id and did following process for deducting it from current year.

    var date=component.find('DOB').get('v.value');
    var splite= date.split('-');
    var num=parseInt(splite[0]);
    var today = new Date();
    var currentYear = today.getFullYear(); //system generated todays date(year)...
    var ageDifference=currentYear -num;

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos