Idea for SetFieldValue for datetime columns
- This topic has 2 replies, 2 voices, and was last updated 3 years, 4 months ago by .
Viewing 2 reply threads
Viewing 2 reply threads
- You must be logged in to reply to this topic.
Home › Forums › Modern DFFS › Idea for SetFieldValue for datetime columns
Hi Alexander, this idea would be for both modern and classic DFFS. I’m noticing that SetFieldValue for DateTime columns will set the time portion of the date field to the users local time zone rather than the time zone set by the regional settings of the site collection. I need all information entered as a specific time zone, is there any way to enforce that functionality?
Example, the site collection is set to Central Time and it’s 3pm right now. I had a user in Pacific Time which is 2 hours behind Central Time so the SetFieldValue rule set the timestamp for 1pm instead of 3pm.
Thoughts?
For reference, this was being done when I had a rule to set the date field value to [today]#now
You can try setting it like this:
Classic DFFS:
let d = new Date();
console.log("Client date:", d);
d.setHours(d.getHours()-(_spPageContextInfo.webTimeZoneData.Bias - _spPageContextInfo.webTimeZoneData.DaylightBias) / 60);
console.log("Server date:", d);
spjs.utility.setDateFieldFromDateObject("DateColumn",d);
Modern DFFS
let d = new Date();
console.log("Client date:", d);
d.setHours(d.getHours()-(_spPageContextInfo.webTimeZoneData.Bias - _spPageContextInfo.webTimeZoneData.DaylightBias) / 60);
console.log("Server date:", d);
setFieldValue("DateColumn",d);
Please note that I’m not 100% sure I have the calculation of the “Bias” correct – you might have to change from – to + but you can look at it and see if it makes sense.
Alexander