1. Bjarne Anker
  2. PowerBuilder
  3. Thursday, 16 December 2021 09:45 AM UTC

Hi.

 

I've created a datawindow and using RestClient.retrieve(dw,URL) to fetch data from our API. Works great.

However, there is a small issue regarding datetime and strings.

This is the string in the JSON responsebody containing the datetime: "messageTime": "2021-12-14T08:11:28.7511998+00:00"

And I would like to format it into date + time, "2021-12-14 08:11:28".

Or event better, norwegian format: "14.12.2021 08:11:28" (dd.mm.yyyy hh:mm:ss)

The column in the datawindow has to be string(40) to get the values in the retrieve.

If I change it to datetime, it's missing.

And I only have "[general]" in the format section in the datawindow painter.

The value is blank if I change it to something else.

 

Is there some sort of format that can help me here, or another workaroud?

 

Regards,

 

Bjarne Anker

Maritech Systems AS

Norway

 

Accepted Answer
Kevin Ridley Accepted Answer Pending Moderation
  1. Friday, 17 December 2021 15:14 PM UTC
  2. PowerBuilder
  3. # Permalink

I think part of the problem is that PB still can't handle the new Time format (maybe create a bug for it?).  You should be able to create a computed field that is DateTime(yourstringfield), but it doesn't work with the new datetime format.  First saw this with the old Sybase/SAP implementation and I guess it carried forward.  We always had to have the service provider make the datetime element a string and parse it ourselves.  Anyway, what you can do temporarily is take your value "2021-12-14T08:11:28.7511998+00:00" and get rid of the T and +00:00 at the end, you can use the DateTime function and it will give you a good value.  So change the T to space and eliminate the + and beyond.  It's a pain, but it will work.  You can probably create a global function that can be used in a computed field expression.

Comment
  1. Kevin Ridley
  2. Tuesday, 21 December 2021 17:30 PM UTC
If you do create a bug, be sure to mention that the DateTime function doesn't work correctly either for new datetime formats.

DateTime(newdatetimeformat) where newdatetimeformat is a string similar to that the op posted.
  1. Helpful
  1. Chris Pollach @Appeon
  2. Tuesday, 21 December 2021 18:19 PM UTC
Hi Kevin ... FYI there is already a support ticket & enhancement request for the time zone issue support in PB vs JSON.
  1. Helpful 2
  1. Kevin Ridley
  2. Tuesday, 21 December 2021 19:22 PM UTC
Awesome, thanks Chris!
  1. Helpful
There are no comments made yet.
mike S Accepted Answer Pending Moderation
  1. Thursday, 16 December 2021 14:32 PM UTC
  2. PowerBuilder
  3. # 1

there is no timezone concept in PB, and thus no way to take that json data (string) and format it as a datetime data type. You have to write your own conversion.

This is missing functionality in PB that is getting more apparent now with easy rest api processing.

 

 

this explains the format:

[MS-ES3EX]: Date Time String Format for JSON | Microsoft Docs

Comment
  1. Chris Pollach @Appeon
  2. Thursday, 16 December 2021 15:15 PM UTC
Correct Mike.
  1. Helpful
  1. Roland Smith
  2. Friday, 17 December 2021 16:20 PM UTC
It can be done with Windows API functions. This example has some of them: https://www.topwizprogramming.com/freecode_filesys.html
  1. Helpful 2
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.