Parse/Convert JSON Date format

Stimulsoft Reports.JS discussion
galexandre
Posts: 7
Joined: Wed Oct 10, 2018 12:32 pm

Parse/Convert JSON Date format

Post by galexandre »

Has anyway to convert Json date format (e. g. 2017-10-05T02:49:26.283) to Date/DateTime format? I load my report from JSON, but my date field is invalid to DateToStr Function.

JSON sample:

{
"id": "105",
"register": "2017-10-05T02:49:26.283",
}
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Parse/Convert JSON Date format

Post by Lech Kulikowski »

Hello,

In the JS version, the only Date is supported in the DateTime field.

Thank you.
galexandre
Posts: 7
Joined: Wed Oct 10, 2018 12:32 pm

Re: Parse/Convert JSON Date format

Post by galexandre »

I'm still working on the designer with json payload. So ... does this mean that you will not be able to create reports using json with data type date? Json dates are texts and do not become DateTime without programming ... I saw the event session and could not handle, they were not fired, at least in the designer. What would be the recommendation for this use case?
Lech Kulikowski
Posts: 6197
Joined: Tue Mar 20, 2018 5:34 am

Re: Parse/Convert JSON Date format

Post by Lech Kulikowski »

Hello,

Please send us a simple report with test data which reproduces the issue for analysis.

Thank you.
galexandre
Posts: 7
Joined: Wed Oct 10, 2018 12:32 pm

Re: Parse/Convert JSON Date format

Post by galexandre »

I noticed that the date type issue only happens in Designer Preview. In Stimulsoft Viewer the problem does not happen. I still do not know what happens when the report runs in an application. Anyway, the DateToStr function wont works. Follow files to validation.
Attachments
Report Date Processing.zip
(19.96 KiB) Downloaded 202 times
galexandre
Posts: 7
Joined: Wed Oct 10, 2018 12:32 pm

Re: Parse/Convert JSON Date format

Post by galexandre »

I occasionally found that it is possible to use {Convert.ToDateTime (dataSource.dataField)} in an expression to convert a string type to DateTime. So for those who use Report.JS, it is possible to convert a JSON date field using this expression.:

Code: Select all

{Convert.ToDateTime(root.datePedido)}
And using builtin function:

Code: Select all

{DateToStrPtBr(Convert.ToDateTime(root.dataPedido))}
So we can consider this post as resolved. However, if there is another alternative, please share it.
galexandre
Posts: 7
Joined: Wed Oct 10, 2018 12:32 pm

Re: Parse/Convert JSON Date format

Post by galexandre »

Another alternative to Convert.ToDateTime is DateTime.Parse() method.
Andrew
Posts: 4104
Joined: Fri Jun 09, 2006 3:58 am

Re: Parse/Convert JSON Date format

Post by Andrew »

Hello,

Thank you very much for the detailed explanation of solutions that you found.

Have a nice day!
Thank you.
zlatinejc
Posts: 1
Joined: Fri Nov 09, 2018 10:47 am

Re: Parse/Convert JSON Date format

Post by zlatinejc »

galexandre wrote: Fri Oct 12, 2018 7:08 pm I occasionally found that it is possible to use {Convert.ToDateTime (dataSource.dataField)} in an expression to convert a string type to DateTime. So for those who use Report.JS, it is possible to convert a JSON date field using this expression.:

Code: Select all

{Convert.ToDateTime(root.datePedido)}
And using builtin function:

Code: Select all

{DateToStrPtBr(Convert.ToDateTime(root.dataPedido))}
So we can consider this post as resolved. However, if there is another alternative, please share it.
I hope they give you free licence since you are teaching them how to debug their own software :shock:
Andrew
Posts: 4104
Joined: Fri Jun 09, 2006 3:58 am

Re: Parse/Convert JSON Date format

Post by Andrew »

Hello,

Yes, we have such a practice to provide free licenses for being active on the forum. So be active and we will grant you with the free license.

Thank you.
Post Reply