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 <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.

  • 1
    you can try format() function of Date apex class – sfdc_sk Mar 14 '19 at 6:20
  • @sfdc_sk, cud u let me know how in lightning component we can do this – john D Mar 14 '19 at 6:35

I don't know of any Datetime to Date conversion function in lightning, but there is an easy solution server side; add a "dateBegin" to your effectivePeriod object that is the date component of your date time then use that in your formattedDateTime call instead. This might ultimately come from a formula field using the DATEVALUE formula function against the datetimeBegin value's field.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.