cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Learn all about PTC Community Badges. Engage with PTC and see how many you can earn! X

DateTime stored in long form getting converted to utc. How to prevent this default behaviour.

MD_10945249
4-Participant

DateTime stored in long form getting converted to utc. How to prevent this default behaviour.

I have this service getprocessdata which returns START_DATE and COMPLT_DATE.
I am calling this service inside of another service that generates report where I need to display start and complete date coming from my getprocessdata service, but the date time  getting returned is in utc.
I also created a demoservice where I called the same service getprocessdata and printed the start_date keeping the output set to dateTime, the output was as expected.
why is such conversion taking place.

Things I have tried:

  • converting the obj.entry storing start and end date to date time, long but still getting date time in utc 

  • used var start_date = new Date(table_start_Date); still getting in utc

Could someone please help me out on how to prevent this date time conversion.
Thank you in advance.

ACCEPTED SOLUTION

Accepted Solutions

Dates are stored in UTC so it's easy to compare them when e.g. querying for a date. The format in which they were entered is not retained - as far as I know.

If you have a timezone, maybe from the user session, you can convert e.g. like this:

new Date().toLocaleTimeString('en-US',{timeZone: 'America/Denver'})

View solution in original post

5 REPLIES 5
Velkumar
19-Tanzanite
(To:MD_10945249)

Hi @MD_10945249 

 

You can dateFormat function to convert dateTime to formatted string

 

let dateTimeValue = new Date();
let result = dateFormat(dateTimeValue,"dd/MM/yyyy HH:mm");

 

Velkumar_0-1717417450742.png

 

/VR

 

MD_10945249
4-Participant
(To:Velkumar)

This is to format the date but I what I want to achieve is to transform my Start_Date comming from a service that is in utc to be converted to the date and time of zone in which it was entered.

Dates are stored in UTC so it's easy to compare them when e.g. querying for a date. The format in which they were entered is not retained - as far as I know.

If you have a timezone, maybe from the user session, you can convert e.g. like this:

new Date().toLocaleTimeString('en-US',{timeZone: 'America/Denver'})

Hi @MD_10945249 

 

The mashup will always show a date field in the current users time zone but are stored/created as UTC.  If you need to display the date in the Time Zone of the user that set it I would recommend one of the following.

  • Create a second property
    • CreatedTZ (created time zone) or
    • CreatedFormated

Then in your report you can either pull the entered date and convert based on CreatedTZ or pull the formatted value from CreatedFormated.  Using the CreatedFormated property approach is assuming the date isn't changed after entered or additional update logic would be needed.

 

Thanks,

 

Travis

Hello @MD_10945249

 

It looks like you have some responses from some community members. If any of these replies helped you solve your question please mark the appropriate reply as the Accepted Solution. 

Of course, if you have more to share on your issue, please let the Community know so other community members can continue to help you.

Thanks,
Community Moderation Team.

Announcements


Top Tags