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
Jonathan Wolff 7Jonathan Wolff 7 

Todays Date in Lightning Component

Hi, I would like to add the todays date next to the "Heute" title. Could you tell me how to insert it in the code below?
User-added imageUser-added image
Best Answer chosen by Jonathan Wolff 7
CharuDuttCharuDutt
Hii Jhonathan Wolf
Try The Below Code
<aura:component>
    <!--Declare Attribute-->
    <aura:attribute name="currentDate" type="string"/>
    <aura:attribute name="TommorowDate" type="string"/>
    
    <!--Declare Handlers-->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <!--Component Start-->
    <div style='font-size:18px; font-weight:bold;'>
       
           Heute ( {!v.currentDate} )
                                    
    </div>
    <div style='font-size:18px; font-weight:bold;'>
       
           Morgen ( {!v.TommorowDate} )
                                    
    </div>
    <!--Component End-->
</aura:component>

({
    doInit : function(component, event, helper) {
        var today = new Date();
        var date = today.getDate();
        var tommorowdate = today.getDate()+1;
        var month = today.getMonth()+1;
        var year = today.getFullYear();
        var result = date +'/'+month;
        var result2 = tommorowdate +'/'+month;
        component.set('v.currentDate', result);
        component.set('v.TommorowDate', result2);
    }
})

Please Don't Forget To Mark it As Best Answer If It Helps
Thank You!

All Answers

Jonathan Wolff 7Jonathan Wolff 7
Hi , thank you for your help, could you just help me with the issues I have with it.
I would like to have the date just 13.4 instead of 13/4/2021 , means in other form and without the year. In addition, could you tell me how to make the same for tomorrows date and the day after tomorrow?

Thank you for your great help
Greetings
Jonathan
CharuDuttCharuDutt
Hii Jhonathan Wolf
Try The Below Code
<aura:component>
    <!--Declare Attribute-->
    <aura:attribute name="currentDate" type="string"/>
    <aura:attribute name="TommorowDate" type="string"/>
    
    <!--Declare Handlers-->
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    
    <!--Component Start-->
    <div style='font-size:18px; font-weight:bold;'>
       
           Heute ( {!v.currentDate} )
                                    
    </div>
    <div style='font-size:18px; font-weight:bold;'>
       
           Morgen ( {!v.TommorowDate} )
                                    
    </div>
    <!--Component End-->
</aura:component>

({
    doInit : function(component, event, helper) {
        var today = new Date();
        var date = today.getDate();
        var tommorowdate = today.getDate()+1;
        var month = today.getMonth()+1;
        var year = today.getFullYear();
        var result = date +'/'+month;
        var result2 = tommorowdate +'/'+month;
        component.set('v.currentDate', result);
        component.set('v.TommorowDate', result2);
    }
})

Please Don't Forget To Mark it As Best Answer If It Helps
Thank You!
This was selected as the best answer
Jonathan Wolff 7Jonathan Wolff 7
So for the day after tomorrow can I just try :
var aftertommorowdate= today.getDate()+2

Greetings
I will mark you as best answer
Jonathan :)
Jonathan Wolff 7Jonathan Wolff 7
Hi, will the code also work on the last day of the month? I am afraid that in the tomorrow component it will show 1.4.21 instead of 1.5.21 . Will it work?
CharuDuttCharuDutt
Hii Jhonathan Wolf
var aftertommorowdate= today.getDate()+2
Yes It Will Work