Convert (UNIX-)Timestamp

Stimulsoft Reports.WEB discussion
Post Reply
hydrant
Posts: 7
Joined: Mon Nov 14, 2022 8:08 am

Convert (UNIX-)Timestamp

Post by hydrant »

Hello,
is there a way to convert a (Unix)Timestamp like 170255541600 in a report to an readable Format?
Thanks
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Convert (UNIX-)Timestamp

Post by Lech Kulikowski »

Hello,

In the Compilation mode (CalculationMode property), you can use the FromUnixTimeSeconds method:
{DateTimeOffset.FromUnixTimeSeconds(170255541600)}

https://learn.microsoft.com/en-us/dotne ... tem_Int64_

Thank you.
Attachments
Screenshot 2024-01-17 025330.png
Screenshot 2024-01-17 025330.png (87.41 KiB) Viewed 1560 times
aletopo
Posts: 3
Joined: Fri Apr 05, 2024 1:08 pm

Re: Convert (UNIX-)Timestamp

Post by aletopo »

Hi there,

It seems this way of conversion uses .NET framework methods. It works fine when generating a single report from desktop application, but fails in batch processing (fields remain empty).
For batch processing we are using a Node.js based server. I assume all .NET framefork methods like DateTimeOffset.FromUnixTimeSeconds() don't work this way.

Any easy alternatives known or any suggestions?

Thank you in advance.
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Convert (UNIX-)Timestamp

Post by Lech Kulikowski »

Hello,

You can add your own function in the report Dictionary:
https://www.stimulsoft.com/en/documenta ... ctions.htm

Thank you.
aletopo
Posts: 3
Joined: Fri Apr 05, 2024 1:08 pm

Re: Convert (UNIX-)Timestamp

Post by aletopo »

Hello,
Thank you, this was the decisive hint and it works when sending a request to the reporting server :-)
Unfortunately the stimulsoft.viewer still fails to recognize the function. Eventually some more configuration needed?
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Convert (UNIX-)Timestamp

Post by Lech Kulikowski »

Hello,

DId you add your own function and this function is not working in the viewer?

Thank you.
aletopo
Posts: 3
Joined: Fri Apr 05, 2024 1:08 pm

Re: Convert (UNIX-)Timestamp

Post by aletopo »

Yes, this is the code integrated in the server.js file:

Code: Select all

function unixToISO(timestamp) {
  iso = new Date(timestamp).toISOString();
  return iso;
};
Stimulsoft.Report.Dictionary.StiFunctions.addFunction("Unix", "unixToISO", "unixToISO", "Description", "", String, "", [Number], ["timestamp"], [""], unixToISO);
Thank you.
Lech Kulikowski
Posts: 6271
Joined: Tue Mar 20, 2018 5:34 am

Re: Convert (UNIX-)Timestamp

Post by Lech Kulikowski »

Hello,

We couldn't reproduce the issue.
Please send us a sample project that reproduces the issue for analysis.

Thank you.
Post Reply