Category: JS Objects
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

How to Convert UNIX Timestamp (Ms) to German Date String in Appsmith

Issue

As an individual, I am trying to display a UNIX timestamp (ms) as a string in German format using a DB-Fef. Currently, my code displays the timestamp in a different format. I am looking for a solution and have tried using moment, but it doesn't seem to be working. I am seeking assistance and would appreciate any suggestions.

Resolution

When working with database records in Appsmith, you may encounter date values stored as UNIX timestamps (milliseconds). If you need to display these dates in a human-readable format, such as German date format (DD.MM.YYYY), you can use the moment.js library.
 

Example Setup

Suppose you have a Table widget named `T2_Tab_Code`, and one of its columns (`Date`) contains UNIX timestamps in milliseconds. To display the date in German format:
{{ moment(new Date(T2_Tab_Code.selectedRow.Date)).format("DD.MM.YYYY") }}

Explanation

  • T2_Tab_Code.selectedRow.Date: Accesses the timestamp value from the selected row.
  • new Date(...): Converts the millisecond timestamp into a JavaScript Date object.
  • moment(...).format("DD.MM.YYYY"): Formats the date into the desired German style.

Alternative Without new Date

If the timestamp is already being parsed correctly by moment, you can simplify:

{{ moment(T2_Tab_Code.selectedRow.Date).format("DD.MM.YYYY") }}
 

Note: Ensure that the column type in your table is returning a valid number (milliseconds). If the format is inconsistent, you may need to preprocess the data in your query or transform it in Appsmith.