We have updated Flexmonster Software License Agreement, effective as of September 30, 2024. Learn more about what’s changed.

How to work with date and time fields

Re-Open
Support Desk asked on November 4, 2022

We are passing large volume of dates to FM in Unix timestamp. Our goal is to calculate some additional fields.
Questions:

  1. How to properly display time sent over as Unix time stamp using FM? For example, 1667542118 to be shown as 2022-11-04 or 1667542175 as 2022-11-04 01:09:35?
  2. How to find number of days between two dates 2022-11-04 and 2022-11-18?

One of the option is process data on the server and send it to the browser, however, it increase the download and processing times. We are setting threshold on the server and want to color code the output. For example, if difference between 2 dates is larger than 35, we want to highlight the cell.

2 answers

Public
Nadia Khodakivska Nadia Khodakivska Flexmonster November 7, 2022

Hello,

Thank you for contacting us.

Please find the answers to your question below:

1. Kindly note that Flexmonster is expected to receive a Unix time stamp in milliseconds. It means that to display 1667542118000 as 2022-11-04, the timestamp should be multiplied by 1000.
Also, it is only possible to set one type per field. We recommend using mapping to customize the presentation of the dates. To make date fields be interpreted as a date, you must define the data type as a date. For example, "type": "datetime" is used to display 1667542175000 as 04/11/2022 08:09:35. However, you can set a special date format. For example,

"Date": {
  type: "datetime",
    format: "yyyy-MM-dd hh:mm:ss"
},

Please check the following JSFiddle for reference: https://jsfiddle.net/flexmonster/c6donx1u/ 

2. If you want to have a field with the number of days between two dates in a large dataset, the recommended way is to do all the calculations on your server side and pass the results to Flexmonster. For instance, you can preprocess the data by calculating the difference between dates and pass those numbers in the new field "Difference between the dates".
Alternatively, you can create a calculated value based on the fields with the "datetime" type. Please note that with this approach, those values will be calculated on the client side. You are welcome to check the following JSFiddle for reference: https://jsfiddle.net/flexmonster/h42br5Lk/ 
When you have this field in the dataset, you can use Conditional Formatting to highlight the necessary cells.

Please let us know if it works for you. Feel free to contact us if other questions arise.

Kind regards,
Nadia

Public
Support Desk November 7, 2022

Thank you. Will try.  It is not clear why the Unix time stamp has been altered 🙁 Normally standards are designed to be what they are, universal.  https://en.wikipedia.org/wiki/Unix_time
Our team will try to build the layout taking in consideration the details we got.  We'll let you know if it worked.

Please login or Register to Submit Answer