Share via

Azure APIM - incorrect date format

Edem, Sai 0 Reputation points
2023-03-31T18:28:14.6066667+00:00

Hi,
Iam trying to retrive data from database via api, below is the code .We have a column whose type is timestamp_ntz which is like 2019-07-02T00:00:00Z . But when i get data via api it is like 1653651822.253000000. Please help me on what changes needs to be done in the below code .

<set-body template="liquid">{    
                            "statement": "select  * from xxxxxxxx;",
                            "timeout": 180,
                            "resultSetMetaData": {
                                "format": "json"
                            },
                            "database": "xxxxx",
                            "schema": "xxxx",
                            "warehouse": "xxxxx",
                            "role": "xxxx"
                            
                   
 }</set-body>

Azure API Management
Azure API Management

An Azure service that provides a hybrid, multi-cloud management platform for APIs.


1 answer

Sort by: Most helpful
  1. MuthuKumaranMurugaachari-MSFT 22,451 Reputation points Moderator
    2023-04-03T14:09:19.03+00:00

    Edem, Sai Thanks for posting your question in Microsoft Q&A. Based on my understanding, your backend API is returning data as 1653651822.253000000 (epoch timestamp) and you would like to convert it to date format using liquid template in APIM.

    APIM uses dotliquid library (.NET implementation of Ruby liquid) for its liquid implementation and unfortunately, this is not supported. Here is reference: Unix epoch string support and we have similar thread discussion: Convert Unix timestamp to human-readable date using Liquid in APIM policy. Alternatively, you can use policy expression in C# 7 and should be able to convert epoch timestamp to date format with expression like below:

    <set-variable name="xxx" value="@(new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(1653651822.253000000).ToString("o"))" />
    

    Reference: https://www.epochconverter.com/

    I hope this helps with your question and let me know if you have any other.


    If you found the answer to your question helpful, please take a moment to mark it as "Yes" for others to benefit from your experience. Or simply add a comment tagging me and would be happy to answer your questions.

    Was this answer helpful?

    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.