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
Matt Brown 71Matt Brown 71 

dataTable date and time

I haven't been able to find anything on this, and surely I can't be the only one but is there any way to show a date and time timestamp in dataTable?  I only see the type 'date'.  Am i just blind or missing something?  I feel like there should be a way to show a formatted date AND time stamp, is there not?
Best Answer chosen by Matt Brown 71
Matt Brown 71Matt Brown 71
Ahh, found the answer here https://sfdcpanther.wordpress.com/2018/01/02/top-10-features-for-lightning-development-spring-18-release/

The short answer is you use date for type, then use typeAttributes fro the column.  Mine now looks like this:
 
{ 
  label: 'Timestamp', 
  fieldName: 'status_timestamp', 
  type: 'date', 
  typeAttributes: {
    day: 'numeric',
    month: 'short',
    year: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    hour12: true
  },
  sortable: false
},
which yields a result like the following: Oct 29, 2018, 9:43:06 AM.

All Answers

MagulanDuraipandianMagulanDuraipandian
Check this - https://www.infallibletechie.com/2018/10/datetime-datatype-in-lightning-datatable.html.

It is supported.
Matt Brown 71Matt Brown 71
Thanks for your answer, however Lightning does nothing special with datetime.  You can achieve the same output by putting any unsupported type for the column.  For example, I get the same ugly timestamp when I use string for the type as when I use datetime for the type.  So datetime isn't actually getting any special formatting or treatment when I use it.
 
Matt Brown 71Matt Brown 71
Ahh, found the answer here https://sfdcpanther.wordpress.com/2018/01/02/top-10-features-for-lightning-development-spring-18-release/

The short answer is you use date for type, then use typeAttributes fro the column.  Mine now looks like this:
 
{ 
  label: 'Timestamp', 
  fieldName: 'status_timestamp', 
  type: 'date', 
  typeAttributes: {
    day: 'numeric',
    month: 'short',
    year: 'numeric',
    hour: '2-digit',
    minute: '2-digit',
    second: '2-digit',
    hour12: true
  },
  sortable: false
},
which yields a result like the following: Oct 29, 2018, 9:43:06 AM.
This was selected as the best answer