web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

Javascript to set today datetime timezone issue

(0) ShareShare
ReportReport
Posted on by 28,983 Moderator
Hi Experts, We have ActualStartDate field on Form and onLoad we are setting today date using JS to this field. Below is the code snippet.
var d =new Date();
Xrm.Page.getAttribute("ActualStartDate").setValue(d);
Xrm.Page.data.entity.save();
PC Timezone - IST
CRM Logged in User Timezone - EST
Issue: Date() object is taking System DateTime which is in IST and while storing the date in UTC in Database, CRM System using EST which is CRM logged in User TimeZone to deduct/add hours based on timezone offset instead of IST.
Example:
System Current DateTime: 4/2/2019 12:22 PM IST
Date() object Time: 4/2/2019 12:22 PM IST
SQL DB field DateTime UTC: 4/2/2019 17:22 PM [Date() + 5 hours EST(UTC-5)]
Solution Proposed to Business:-
  1. Keep CRM Logged in user TimeZone and PC Timezone same. [This will not ensure 100% result as some user might have different timezone]
  2. Execute Custom Action from onLoad JS and update ActualStartDate from c# code [Performance impact on form load as it was taking more than 1 mins to update the record]
  3. tried converting Date() to UTC in JS but didn't work.
Please provide your inputs. Thanks in Advance!

*This post is locked for comments

I have the same question (0)
  • Verified answer
    David Jennaway Profile Picture
    14,065 on at

    One way to avoid the PC timezone could be to create a calculated field in CRM that just calculates the current date and time, and put this in a hidden field on the form. When the form is loaded, this will be populated with the current date and time, based on the user's CRM timezone. Then set the ActualStartDate field to the value of the calculated field

  • Bipin D365 Profile Picture
    28,983 Moderator on at

    This is working. Thank you very much!

  • Bipin D365 Profile Picture
    28,983 Moderator on at

    Hi David,

    When we tried in Trial account it worked. But when I tried in our DEV On premise it is still giving IST time[PC Time] in JS instead of CRM logged in user timezone based time.

    On Form calculated field is showing correct time but from JS we are still getting System local time.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans