Hi,
Here I'm creating a task using web api JS.
Dynamics CRM always saves "Scheduled Start" & "Scheduled End" as Local Date Time. But I'm getting 13 hours 30 minutes difference between local datetime and saved DateTime.
var objAddTask = {};
var sd = new Date("2018-02-20T00:00:00");
var ed = new Date("2018-02-21T00:00:00");
objAddTask["scheduledstart"] = sd;
objAddTask["scheduledend"] = ed;
stringJSONTask = JSON.stringify(objAddTask);
var oDataSelect = serverUrl + "/api/data/v8.0/tasks";
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: oDataSelect,
data: stringJSONTask,
beforeSend: function (XmlHttpRequest) {
XmlHttpRequest.setRequestHeader("Accept", "application/json");
XmlHttpRequest.setRequestHeader("Content-Type", "application/json; charset=utf-8");
XmlHttpRequest.setRequestHeader("Prefer", "odata.include-annotations=*");
XmlHttpRequest.setRequestHeader("OData-MaxVersion", "4.0");
XmlHttpRequest.setRequestHeader("OData-Version", "4.0");
},
success: function (data, textStatus, XmlHttpRequest) {
alert("success");
},
error: function (xmlHttpRequest, textStatus, errorThrown) {
alert("Status: " + textStatus + "; ErrorThrown: " + errorThrown);
}
Can anybody suggest me?
*This post is locked for comments
Hi Chaya,
Your answer- Convert UTC date time to Pacific Canada and US.
var offset = -8; //For Canada and Pacific set offset
var localdate = new Date(); //Local Time
var utcConvertDate = localdate.toUTCString(); //Convert to UTC
var currnetDate = new Date(utcConvertDate); //Convert to date object
var datePacific = new Date( currnetDate.getTime() + offset * 3600 * 1000).toUTCString().replace( / GMT$/, "" )
console.log(datePacific);
Hope this helps.
Thanks Alex!
I have configured "Pacific Time US & Canada" timezone in options.
var sd = new Date("2018-02-20T13:30:00Z");
Can you please suggest me that how to convert "sd" (UTC datetime) to "Pacific Time US & Canada" timezone.
Thanks Goutam!
I tried that code, but It gives me an error 'Cannot convert the literal '2018-02-20T00:00:00' to the expected type 'Edm.DateTimeOffset'
Can you suggest me another way?
Hi,
wondering if that's consistent with the timezone offset configured in your "options" in Dynamics? In that case you may need to convert those values to UTC time and use timezone (Z):
var sd = new Date("2018-02-20T13:30:00Z");
Hi Chhhaya,
Could you please convert your date as UTC when you are passing.
var d = new Date();
var n = d.toUTCString();
you can refer below link for more information -
community.dynamics.com/.../dynamics-crm-datetimes-the-last-word
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
52
Victor Onyebuchi
6