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
sheila srivatsavsheila srivatsav 

remove time from datetime in lightning

I have a json coming from api and it has a datetime as 2019-01-01T00:00:00-05:00 I am displaying this in lightning component as below .

<lightning:formattedDateTime value="{!medicareValues.effectivePeriod.datetimeBegin}" year="numeric" month="numeric" day="numeric"/
                                                                                              
But I want to remove the time and display the date as 2019-01-01. Please let me know how I can achieve this.

thanks
sheila
Raj VakatiRaj Vakati
You need to use the locationzarionService of Aura framework ..

Refer this link 

https://www.sfdcstuff.com/2017/12/formatting-and-localizing-dates-in.html

https://www.biswajeetsamal.com/blog/salesforce-lightning-formatted-datetime/

https://saramorgan.net/2017/10/01/workaround-for-problem-with-lightninginput-and-datetime-local/

https://salesforce.stackexchange.com/questions/216032/lightningformatteddatetime-changes-the-date/225938
https://developer.salesforce.com/docs/component-library/bundle/lightning:formattedDateTime/documentation
​​​​​​​
 
<lightning:formattedDateTime value="1547250828000" year="numeric" month="numeric" day="numeric"  hour="2-digit" minute="2-digit" timeZoneName="short" />

 
Naveen KNNaveen KN
Hi Sheila,

In case if it is possible, ask your API team to send the format which you need.

If you want to fix it from salesforce side use  <lightning:formattedDateTime value="2019-12-02T00:00:00-05:00" year="numeric" month="numeric" day="numeric"/> stamp your json field value to this field

it will give output as 12/2/2019

or
in the controller, you can use the substring function of javascript to get first 10 characters. 

Naveen