Parse/Convert JSON Date format

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

Parse/Convert JSON Date format

Post by galexandre » Wed Oct 10, 2018 12:56 pm

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: 682
Joined: Tue Mar 20, 2018 5:34 am

Re: Parse/Convert JSON Date format

Post by Lech Kulikowski » Wed Oct 10, 2018 10:31 pm

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

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: 682
Joined: Tue Mar 20, 2018 5:34 am

Re: Parse/Convert JSON Date format

Post by Lech Kulikowski » Fri Oct 12, 2018 2:39 pm

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

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 6 times
galexandre
Posts: 7
Joined: Wed Oct 10, 2018 12:32 pm

Re: Parse/Convert JSON Date format

Post by galexandre » 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.
galexandre
Posts: 7
Joined: Wed Oct 10, 2018 12:32 pm

Re: Parse/Convert JSON Date format

Post by galexandre » Sun Oct 14, 2018 3:11 pm

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

Re: Parse/Convert JSON Date format

Post by Andrew » Mon Oct 15, 2018 3:48 am

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

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: 3756
Joined: Fri Jun 09, 2006 3:58 am

Re: Parse/Convert JSON Date format

Post by Andrew » Tue Nov 13, 2018 8:47 am

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