1
votes

I am fairly new to SharePoint 2013 workflows with years of general C# and other SharePoint experience.

My problem is with timezones. I am developing a list workflow in Visual Studio 2013 which has to take some actions based on the value of a date only field of the current item in the list. I am retrieving the value of this field using GetDynamicValueProperties and assign it to a variable. However if I check this value, I can see that it is not correct as it is 23:00 on the day before the one I actually set for the list item. I am assuming this is because no matter being a date only field, behind the scenes it is still being stored in a regular DateTime object.

Because of this, all my date calculations are 1 day off (because I only use the date part). I have noticed that all the timezone specific classes and methods cannot be used within the workflow.

Is there any way I can correctly retrieve only the date part of this field value without hardcoding any offsets? I am preferably looking for a solution which does not include workarounds and hacks and works in all environments.

Background information: I have to execute tasks n days before this date at a given time (e.g. 8 AM). The second part is tricky too, as the time part will also be 1 hour off because of this. I am looking for a solution for this too.

1

1 Answers

0
votes

Managed to solve it calling the appropriate SharePoint REST API endpoints in an HttpSend activity.

SPTimeZone.utcToLocalTime endpoint

SPTimeZone.localTimeToUTC endpoint

I am passing the original date as an url parameter and receive the converted date in a JSON object which can easily be parsed in the workflow. The conversion occurrs according to the site collection regional settings.

Note: when converting from local to UTC, the result string contains the "Z" character at the end, indicating that it is indeed a UTC date. When parsing the whole string as a DateTime in the workflow, it converts it back to the original date because of this. I have cut the last character using the String.Substring method, and it is working fine now.