This article explains different methods of setting a date value (date variable) using a SharePoint designer workflow. It describes how a date variable can be set to either a static date, a dynamic date, or a calculated date.
Assumptions
- You already have a workflow in which you want to set (or calculate) a date
- You have created a variable named DateVar of type Date/Time in your workflow
A date variable in a SharePoint designer workflow can be set to a specific (or static) date, or it can be set to a calculated (or dynamic) date [for example, today’s date plus 5 days].
Let’s start by showing how to set a date variable either to today’s date or to some specific date.
1. Set A Date Value To Today’s Date Or Some Specified Date
To set the value of our DateVar variable to the current date or some other specific date:
- Add the Set Workflow Variable action to your workflow
- Set the workflow variable parameter to the DateVar variable you previously created
- Click value in the Set Workflow Variable action and then click the ellipsis button
- Select either Current date or Specific date (if you’re setting a specific date, choose the date and/or time from the options)
- Press OK
2. Set A Date Value To The Value Of A Date Column In A List
To set the value of our DateVar workflow variable to the value of a date field in a list (say the Created date field):
- Add the Set Workflow Variable action to your workflow
- Set the workflow variable parameter to the DateVar variable you previously created
- Click value in the Set Workflow Variable action and then click the formula (fx) button
- On the Field from source dropdown, select the Created date field (assuming that’s the date field you want to use)
- Press OK
3. Set A Date Value To The Value Of A Calculation
To set the value of our DateVar workflow variable to the value of a date calculation, for example, to a date that is 5 days from today:
- Create a new variable named TodaysDate of type Date/Time in your workflow
- Add the Set Workflow Variable action to your workflow
- Set the workflow variable parameter to the TodaysDate variable
- Click value in the Set Workflow Variable action and then click the ellipsis button
- Select Current date and press OK
- Add the workflow action called Add Time To Date to your workflow
- Notice that a new Date/Time variable named date has been automatically created for you and used to store the output of the above action. Delete the automatically added variable (to keep things clean) and set the output to the DateVar variable you created earlier
- Click 0 in the text for the action and type 5. Click minutes and select days from the dropdown.
- Click date, click the formula (fx) button
- For the Data source parameter, select Workflow Variables and Parameters
- For the Field from source parameter, select Variable: TodaysDate
- Press OK. The workflow lines will look like this:
NOTE: Trying to combine both lines into one, as shown below won’t work. At least, it didn’t work for me.
Bonus Tip: How To Blank Out A Date Column
You may sometimes need to set the value of a date column to empty or blank or null. You will NOT be able to do this by just plugging in an empty value or a space.
Interestingly, SharePoint requires that you set the date to 1/01/0001 and that you use a variable to do this instead of attempting a direct value assignment.
Why these requirements? I don’t know. That’s just how it is. I discovered it the hard way too 🙁
So here’s how you would go about blanking out a date field:
- Create a workflow variable named EmptyDate
- Using the Set Workflow Variable action (described earlier), set the variable value to 1/01/0001
- Set the date field you want to blank out to the workflow variable EmptyDate
How do I assign a date variable back to a PWA date variable. Nothing seems to work?
This is a great guide on how to do this. Thanks!
Glad I could help.