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
Siva NalamSiva Nalam 

Lightning datatable date field showing one day less when formatted

When using lightning datatable and displaying a date field, its showing a day less than the value in the backend object.

Controller:
component.set('v.Columns',[
                {label:'Transport. mode', fieldName:'Mode_of_Transportation__c', type:'text', editable: false,initialWidth:180},
                {label:'Ground Company', fieldName:'Ground_Transportation_Company__c', type:'text', editable: false,initialWidth:210},
                {label:'Inv./Chg. date', fieldName:'Charge_Invoice_Date__c', initialWidth:150, type:'date', editable: false , typeAttributes:{month:'2-digit',day:'2-digit',year:'numeric'}}
            ]

Datatable:

            <lightning:datatable aura:id="OppExpGTDataTable"
                                 data="{! v.Opp_Expenses_GTXYZ }" 
                                 columns="{! v.Columns }" 
                                 keyField="Id"
                                 onsave ="{!c.onSave}"
                                 hideCheckboxColumn="true"
                                 onrowaction="{! c.handleRowAction }"/>

Using a custom pop up, we are creating records into database capturing date values. Its getting stored in database properly, when displaying in UI, its showing a day less. In out of the box fields, its showing correctly again. How to format the field in lightning datatable/controller? Appreciate your help..
Best Answer chosen by Siva Nalam
Siva NalamSiva Nalam
I found a solution:

If we use type:'date-local' instead of type:'date', its showing correct date. For the benefit of others, here is the link that helped:

https://salesforce.stackexchange.com/questions/221698/help-with-working-with-lightningdatatable/244352#244352

 

All Answers

Siva NalamSiva Nalam
I found a solution:

If we use type:'date-local' instead of type:'date', its showing correct date. For the benefit of others, here is the link that helped:

https://salesforce.stackexchange.com/questions/221698/help-with-working-with-lightningdatatable/244352#244352

 
This was selected as the best answer
kuro himekuro hime
thanks for the advice!
https://mathsolver.pro/mathway/
ghd sports 2ghd sports 2
I recently found more information on https://developer.salesforce.com/forums/?id=9062I000000g5qGQAQ&feedtype=SINGLE_QUESTION_DETAIL&dc=Lightning&criteria=BESTANSWERS& - more of the people provides the best answer and best solutions check out here -  regards - Gomaxtv (http://gomaxlivetv.com/)
Fred13Fred13
Thank you for this.  I had two date fields on my LWC.. one was ok and the other was not.  Using Date-Local fixed the issue.   Thanks again!!!