Forums

Forums / Developing Portals / Convert Date Time format UTC to Local User time Zone

Convert Date Time format UTC to Local User time Zone

Thread is closed for posting
4 posts, 2 answered
  1. Muhammad Bilal
    Muhammad Bilal avatar
    1 posts
    Registered:
    10 Feb 2020
    10 Feb 2020
    Link to this post
    Hi,

    We have a date time column in custom grid getting date time column from Dynamics 365 using FetchXml, the coming date time format in UTC, this format isn't working for us for filter the records, we need date time columns in Local User Time Zone, can i do it using format in Grid's Settings.? if yes then what will be the supported format for it.

    Any help will be appreciated.
    Many Thanks
  2. Josh
    Josh avatar
    47 posts
    Registered:
    01 Jun 2018
    Answered
    18 Feb 2020 in reply to Muhammad Bilal
    Link to this post
    Hello Muhammad,

    Are you using a TPC Grid? If so, it is correct that the dates are being passed to the front-end as an ISO UTC string. This format would look something like the following: "2018-05-01T20:22:54.000Z".

    If the dates are not being passed in this format, we would recommend that you upgrade to The Portal Connector version 5.3, as we have completely re-built the way the application handles dates.

    Fetch XML is filterable using an ISO string as shown above (the default way that The Portal Connector passes dates to the grid). For example, the following fetch is valid and returns me many records.

    <fetch version="1.0" mapping="logical" output-format="xml-platform">
      <entity name="account">
        <attribute name="name" />
        <attribute name="primarycontactid" />
        <attribute name="telephone1" />
        <attribute name="accountid" />
        <attribute name="createdon" />
        <order attribute="name" descending="false" />
        <filter type="and">
          <condition attribute="createdon" operator="eq" value="2018-05-01T20:22:54.000Z" />
        </filter>
      </entity>
    </fetch>
    

    Are you calling this functionality through custom JavaScript? If so, you can pass the UTC (ISO String) to the JavaScript Date object and it will automatically create a Date in the users local timezone.

    var localDate = new Date("2018-05-01T20:22:54.000Z")
    

    From this Date object, you can use standard Date.ToString() or Date.toLocaleDateString() and create any date format you would like.
    It is not recommended to format the Date using the Grid column settings (server-side), as this will ignore the users local time zone. 

    It is possible to format the dates on the client-side, this will simply require some custom JavaScript. Below is a working example of how to use Kendo Date formatting to format the date of a column in a TPC Grid.

    //Obtain Grid
    var grid = tpc.page.TpcGridModel.get_grid();
    
    /* -------------------------------------------------------------
    Standard Date Format
    ---------------------------------------------------------------*/
    
    //Set Date Column Format
    grid.columns[6].format = "{0:d}";
    
    //Set Options
    grid.setOptions({ 
        columns: grid.columns 
    });
    
    /* -------------------------------------------------------------
    Custom Date Format
    ---------------------------------------------------------------*/
    
    //Set Date Column Format
    grid.columns[6].format = "{0: yyyy-MM-dd HH:mm:ss}";
    
    //Set Options
    grid.setOptions({ 
        columns: grid.columns 
    });
    

    More information on Kendo Date formatting can be found here: https://docs.telerik.com/kendo-ui/globalization/intl/dateformatting.

    Hopefully this information is useful and will help you to solve your FetchXML issue. Please let me know if you have any other questions or email us at support@crmportalconnector.com if you need more help.

    Thank you,

    Josh

  3. Josh
    Josh avatar
    47 posts
    Registered:
    01 Jun 2018
    19 Feb 2020 in reply to Muhammad Bilal
    Link to this post
    It has been brought to my attention that the TPC Grid Column formatting should also work, although it appears an issue has been introduced in The Portal Connector 5.3 that is preventing TPC Grids from formatting DateTime columns.

    The custom JavaScript formatting provided earlier can be used as a work-around until we have fixed this issue.

    I will update this forum post when the issue haws been resolved.

    Thank you for your patience,

    Josh
  4. Josh
    Josh avatar
    47 posts
    Registered:
    01 Jun 2018
    Answered
    20 Feb 2020 in reply to Muhammad Bilal
    Link to this post
    The DateTime column formatting issues for the TPC Grid have been corrected and are part of the latest build(s) outlined below.

    The Portal Connector 5.3 – Minor Version 102 (currently available)
    The Portal Connector 5.2 – Minor Version 121 (will be available by end of day – Feb 20)


    Once you update to the latest build, you should be able to use the column formatting in the TPC Grid Settings (Grid -> Edit -> Columns)

    Please let me know if this issue persists after updating, or you have any other issues.

    Thanks,

    Josh
4 posts, 2 answered