Date() of a DateTime jumps back a day - assumed because of daylight savings

This follows on from trying to calculate number of days until a deadline. This could be an issue due to daylight savings.

In my workflow I have a variable that picks up the Target Time attribute. I then use the Date() computational helper to convert that to a Date but it is giving the wrong date in places when the Target Time is set to midnight BST:

  • 15 April 2024 15:30 → 15/04/2024 Correct
  • 10 April 2024 01:00 → 10/04/2024 Correct
  • 27 March 2024 00:00 → 27/03/2024 Correct - during winter before clocks change
  • 11 April 2024 00:55 → 10/04/2024 INCORRECT - changes to the day previously.

I have tried using the Ceiling() computational helper to round the Target Time up to the end of the day. I have tried this using Ceiling(targetTime, Min) but I end up with the error:

"error": {
                "category": "WorkflowMalformed",
                "errorCode": "E1586175934",
                "errorData": {
                    "missingReferences": [
                        {
                            "definition": "variable 'ceilingTime'",
                            "missingReferencedVariables": [
                                "Ceiling",
                                "Min"
                            ]
                        }
                    ]
                },
                "httpStatusCode": 400,
                "message": "In action designs_workflowEditItemAction, there are references to variables that do not exist."
            },

What is the appropriate way to manage DateTimes across daylight savings or round up to the end of the day.

Hi Chris, you are indeed correct, the discrepancies you are seeing happen because of daylight savings and because all DateTimes we store are in UTC. My suggestion would be to convert all dates to local time first, before doing the calculation. Following from your example in your previous post, using the below as your variables will hopefully do the trick.

 "variables": [
    {
      "name": "targetTime",
      "value": {
        "inputParent": 0,
        "itemValue": {
          "attributeCode": "attributes_tasksTargetTime",
          "discriminator": "WorkflowSyntaxArgumentItemValueAttributeWebModel"
        },
        "discriminator": "WorkflowSyntaxNodeInputWebModel"
      }
    },
    {
      "name": "daysToTarget",
      "value": {
        "discriminator": "WorkflowSyntaxNodeScriptWebModel",
        "script": "var localTarget = DateTimeMath.Floor(Local(targetTime.Value), DateTimeMath.Day); var localNow = DateTimeMath.Floor(Local(Now), DateTimeMath.Day); return (localTarget.Value - localNow.Value).Days;"
      }
    }
  ],

There should be no need for further calculations, just use the variable daysToTarget.
That will work only if the passed Task has the attributes_tasksTargetTime populated with an actual date, which as I recall from your previous post you have already fixed.

1 Like