4

Why do I lose 4 hours when converting a date to a double and back again in a SharePoint designer workflow? More importantly, what's the proper way to do a date calculation in a workflow? Most importantly, why is SharePoint the worst and no one noticed?

I'm creating a SharePoint 2010 workflow in Designer 2013 (evidently because Satan won). I need to find a date based on a Date Time column called Due Date. I've mutilated my workflow so much trying to figure out what's going on that I'm not sure of the original process. I think I created a Number variable called NewDate from Due Date then calculated Date Column as NewDate minus 1209600 (2 weeks).

If Due Date is the 19th at 12:00:00 am, Date Column comes out as the 4th at 8:00:00 pm, instead of the 5th at 12:00

More interesting is if I cast Due Date to a number and then back to a date, I get the 18th at 8:00:00pm

 DueDate as Date - 2015-05-19 12:00:00 AM  

 DueDate as Date to Double - 3640982400  

 Due Date as Date to Double to Date - 2015-05-18 8:00:00 PM 

As SharePoint is exhausting, I could be missing something simple. Or it's another simple thing Microsoft missed. How are we meant to calculate dates in a workflow?

I could just add 4 hours but I feel like that's the kind of kludge I for some reason refuse to learn is what SharePoint solutions are made of

  • Have you tried using Add time to Date Action? And set it like Add -14 Days to DueDate (Output to Variable: YourDateVariable) – Amal Hashim May 12 '15 at 19:51
  • that sounds much better than the suggestion I was going with – user1566694 May 12 '15 at 20:00
  • i gain 4 hours when i log the date, but the date itself is right. suddenly i have a good feeling about making a workfow that waits for a non fixed date – user1566694 May 12 '15 at 20:47
  • Cool. I have posted it as an answer. Hope it helps. – Amal Hashim May 12 '15 at 21:19
7

For date calculations you can use workflow action Add time to Date Action

In your case it will be like Add -14 Days to DueDate (Output to Variable: YourDateVariable). This will substract 14 days from Due Date.

Also note - SharePoint stores date in UTC and it dynamically converts it to Regional time on UI.

  • What if I want to set a date to the 1st of next month? – Christine Nov 29 '16 at 17:59
  • No? Didn't think so. SharePoint sucks. – Christine Jan 9 '17 at 21:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.