Page 1 of 2

Parse/Convert JSON Date format

Posted: Wed Oct 10, 2018 12:56 pm
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",
}

Re: Parse/Convert JSON Date format

Posted: Wed Oct 10, 2018 10:31 pm
by Lech Kulikowski
Hello,

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

Thank you.

Re: Parse/Convert JSON Date format

Posted: Thu Oct 11, 2018 12:32 pm
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?

Re: Parse/Convert JSON Date format

Posted: Fri Oct 12, 2018 2:39 pm
by Lech Kulikowski
Hello,

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

Thank you.

Re: Parse/Convert JSON Date format

Posted: Fri Oct 12, 2018 2:50 pm
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.

Re: Parse/Convert JSON Date format

Posted: Fri Oct 12, 2018 7:08 pm
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.

Re: Parse/Convert JSON Date format

Posted: Sun Oct 14, 2018 3:11 pm
by galexandre
Another alternative to Convert.ToDateTime is DateTime.Parse() method.

Re: Parse/Convert JSON Date format

Posted: Mon Oct 15, 2018 3:48 am
by Andrew
Hello,

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

Have a nice day!
Thank you.

Re: Parse/Convert JSON Date format

Posted: Fri Nov 09, 2018 10:50 am
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:

Re: Parse/Convert JSON Date format

Posted: Tue Nov 13, 2018 8:47 am
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.