Results 1 to 7 of 7

Thread: How to decode Microsoft json (date) format?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2009
    Location
    Perth, Western Australia
    Posts
    1,457

    Default How to decode Microsoft json (date) format?

    Hi,

    In an API we are attempting to consume, the date is being returned as follows;

    Code:
        "queue": [
            {
                "blob_url": "",
                "create_time": "/Date(1668149153303+0000)/",
                "file_name": "17603507.PDF",
                "invoice_id": 17824747,
                "log": "Successfully exported Supplier Invoice"
    According to the developer it is Microsoft Json format and can be decoded as follows:

    Code:
    function parseMSDate(s) {
        // Jump forward past the /Date(, parseInt handles the rest
        return new Date(parseInt(s.substr(6)));
    }
    Does anyone have a DataFlex function, or exposed the MS function, that decodes the above value into something human readable?
    Kind regards,

    Clive Richmond
    Triumph Business Systems Pty Ltd
    www.triumph.com.au

  2. #2
    Join Date
    Feb 2009
    Location
    Hengelo, Netherlands
    Posts
    10,340

    Default Re: How to decode Microsoft json (date) format?

    Clive,

    Could it be a UNIX timestamp? In that case use the DateTime library.
    Regards,
    Data Access Worldwide
    Vincent Oorsprong

  3. #3
    Join Date
    Feb 2009
    Location
    Perth, Western Australia
    Posts
    1,457

    Default Re: How to decode Microsoft json (date) format?

    Vincent,

    Quote Originally Posted by Vincent Oorsprong View Post
    Could it be a UNIX timestamp? In that case use the DateTime library.
    Unfortunately it is not. I have found out it is Javascript. Some info from the w3schools.

    JavaScript Stores Dates as Milliseconds JavaScript stores dates as number of milliseconds since January 01, 1970.

    Zero time is January 01, 1970 00:00:00 UTC.

    One day (24 hours) is 86 400 000 milliseconds.

    Now the time is: 1669012595521 milliseconds past January 01, 1970
    Using their training link it converts the dates correctly into something humanly readable. E.g.

    Code:
    1668149153303 milliseconds from January 01 1970 UTC is:
     Fri Nov 11 2022 14:45:53 GMT+0800 (Australian Western Standard Time)
    Is there a method in the library that can do this conversion? If not, how difficult is it to add one?
    Kind regards,

    Clive Richmond
    Triumph Business Systems Pty Ltd
    www.triumph.com.au

  4. #4
    Join Date
    Feb 2009
    Location
    Hengelo, Netherlands
    Posts
    10,340

    Default Re: How to decode Microsoft json (date) format?

    Clive,

    UNIX timestamps are also based on 1/1/1970 but in seconds. So in theory you could just multiply or divide by 1000 BUT in reality there is more to do as the standard functions to format date & time via the Windows API exclude the milliseconds part. The DataFlex time variable is also without milliseconds.

    But I made a change in the Date & Time library and it can now use a JavaScript datetime stamp. It will be available after the build server produces a new version. It will only be available in 20.1.
    Last edited by Vincent Oorsprong; 21-Nov-2022 at 06:02 AM. Reason: Buildserver, 20.1
    Regards,
    Data Access Worldwide
    Vincent Oorsprong

  5. #5
    Join Date
    Feb 2009
    Location
    Perth, Western Australia
    Posts
    1,457

    Default Re: How to decode Microsoft json (date) format?

    Vincent,

    Quote Originally Posted by Vincent Oorsprong View Post
    But I made a change in the Date & Time library and it can now use a JavaScript datetime stamp. It will be available after the build server produces a new version. It will only be available in 20.1.
    Thanks for making the change. Are you able to advise when the build server will produce a new DataFlex 20.1 version that will be publicly available for download?
    Kind regards,

    Clive Richmond
    Triumph Business Systems Pty Ltd
    www.triumph.com.au

  6. #6
    Join Date
    Feb 2009
    Location
    Hengelo, Netherlands
    Posts
    10,340

    Default Re: How to decode Microsoft json (date) format?

    Clive,

    The new enhanced version is available since yesterday. Have fun with it.
    Regards,
    Data Access Worldwide
    Vincent Oorsprong

  7. #7
    Join Date
    Feb 2009
    Location
    Perth, Western Australia
    Posts
    1,457

    Thumbs up Re: How to decode Microsoft json (date) format?

    Vincent,

    Quote Originally Posted by Vincent Oorsprong View Post
    The new enhanced version is available since yesterday. Have fun with it.
    The new enhancement does exactly what we want. Thank-you. I like the new build server 👏��
    Kind regards,

    Clive Richmond
    Triumph Business Systems Pty Ltd
    www.triumph.com.au

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •