Construct a date from strings in a SharePoint Designer 2010 workflow

Learn how you can use the String Builder in a SharePoint Designer 2010 workflow to concatenate string to form a date and then convert this string to the date and time type.

ADVERTISEMENTS

You have a string that contains a date and a string that contains a time and you want to be able to construct a valid date from these two strings using a SharePoint Designer workflow.

Constructing a date from strings involves two things:

  1. Concatenating string values to form a valid date.
  2. Converting the resulting date string into a date type.

You can use the String Builder dialog box in SharePoint Designer 2010 to concatenate strings.

You can use variables in a SharePoint Designer workflow to easily convert values from one data type to another (for example use a SharePoint workflow to convert a string to a number) and/or to properly format values.

We are going to use the aforementioned two techniques to construct a date from strings as follows:

  1. In SharePoint Designer 2010, create a new List Workflow.
  2. Click Workflow > Variables > Local Variables.
  3. On the Workflow Local Variables dialog box, add the following 4 variables: dateString of type String, timeString of type String, dateTimeString of type String, and dateTimeResult of type Date/Time.
  4. Click Workflow > Insert > Action > Set Workflow Variable and set the dateString variable to a valid date such as for example 2010-12-25.
  5. Click Workflow > Insert > Action > Set Workflow Variable and set the timeString variable to a valid time such as for example 20:54.
  6. Click Workflow > Insert > Action > Set Workflow Variable, set workflow variable to dateTimeString, click value, and then click the ellipsis (...) button.
  7. On the String Builder dialog box, click Add or Change Lookup.
  8. On the Lookup for String dialog box, select Workflow Variables and Parameters from the Data source drop-down list box, select Variable: dateString from the Field from source drop-down list box, and click OK.
  9. On the String Builder dialog box, type T, and then click Add or Change Lookup.
  10. On the Lookup for String dialog box, select Workflow Variables and Parameters from the Data source drop-down list box, select Variable: timeString from the Field from source drop-down list box, and click OK.
  11. On the String Builder dialog box, type :00Z, which results in the final string value of [%Variable: dateString%]T[%Variable: timeString%]:00Z in the Name text box , and then click OK.
  12. Click Workflow > Insert > Action > Set Workflow Variable, set workflow variable to dateTimeResult, click value, and then click the formula button.
  13. On the Lookup for Date/Time dialog box, select Workflow Variables and Parameters from the Data source drop-down list box, select Variable: dateTimeString from the Field from source drop-down list box, leave As Date/Time selected in the Return field as drop-down list box, and click OK.
  14. Click Workflow > Insert > Action > Log to History List, click this message, and then click the formula button.
  15. On the Lookup for String dialog box, select Workflow Variables and Parameters from the Data source drop-down list box, select Variable: dateTimeResult from the Field from source drop-down list box, leave As String selected in the Return field as drop-down list box, and click OK.

    The SharePoint Designer workflow should now resemble the following figure:

    SharePoint Designer 2010 workflow to construct a date from strings

    Figure 1. SharePoint Designer 2010 workflow to construct a date from strings.

  16. Publish the workflow to SharePoint.

If you go to the SharePoint list or library to which you associated the workflow, start the workflow on an item, and then click on the text Completed once the workflow is done running, you should see the date you entered (including a time zone correction depending on the localization of your SharePoint Server) listed under the Description column in the Workflow History list.

Related Articles

ADVERTISEMENTS