Views:

Question:
I'd like to utilize the last day of a given month for assigning a due date, for example. How do I obtain the last day of the month in a workflow?

Answer:
Obtaining the last day of a month can be accomplished by the use of arithmetic expressions. Please consider the following method when implementing this on your system.

Since we do not have a single method that will get us the last day of the month, we'll need to utilize three arithmetic expressions in order to get this value. In our example, we have 3 Text Global Variables created, LastDayOfMonth1, LastDayOfMonth2, and LastDayOfMonth3. We'll be using the following approach,

  • Get the first day of the month we need the last day on.
  • Jump ahead by one month
  • Finally, subtract 1 day in order to get us to the last day of the month we need.

In our Workflow, we'll have an Assign Data step which looks like the following, 

Workflow global variable = Date = Fixed entry = first day of month 
Workflow global variable = LastDayofMonth1 = Arithmetic expressions = Date(GV_Date.Year,GV_Date.Month,1)
Workflow global variable = LastDayofMonth1 = Arithmetic expressions = DateAdd("m", 1, GV_LastDayOfMonth1)
Workflow global variable = LastDayofMonth1 = Arithmetic expressions = DateAdd("d", -1, GV_LastDayOfMonth2)



For testing purposes, a Date Global Variable was created, which provided January as the month that we want the last day of.

Date(GV_Date.Year,GV_Date.Month,1)
This method requires the following parameters, Year, Month, and Day. In our example, we're providing the Year and Month of our date by placing .Year and .Month at the end of our variable to retrieve this information. Since we only need the first day of the month, we'll use 1 as our last parameter.

DateAdd("m", 1, GV_LastDayOfMonth1)
We're using the DateAdd method in order to jump ahead a month, providing "m" as the first parameter to indicate that we want to modify the month, for the second parameter, we'll provide 1 since we want to jump ahead just by one month. Finally, we'll provide our LastDayOfMonth1 variable.

DateAdd("d", -1, GV_LastDayOfMonth2)
Our last step of this process is to subtract one day now in order to get to the last day of our target month, which will once again use the DateAdd method.
Much like the last step, we're using "d" in the first parameter to indicate that we want to change the day, then we're using -1 to subtract a day from our date, then finally providing our LastDayOfMonth2 variable.

When testing this through a workflow you should see the following results shown in the history.

LastDayOfMonth1: 01/01/2023
LastDayOfMonth2: 02/01/2023
LastDayOfMonth3: 01/31/2023
Date: 01/10/2023
 
KBA is applicable for both Cloud and On-premise Organizations 
Comments (0)