Question

I am trying to call REST API Inside a SHAREPOINT Designer Workflow based on a date query.

my filter string is

$filter=Created le '2019-04-28'

however, Instead of the date value, I need a dynamic date of today minus 180 days and in the right format.

I was able to get the 180 days before by adding -180 days to the date variable.

But the date I get is in

"4/28/2019"

format.

Any suggestions on changing the / to - and changing the position of M,D,Y ?

Was it helpful?

Solution 2

I was eventually able to create the date format by extracting separately, all components of the date. by following the below steps

This worked because ISO format luckily had year month and days at fixed character indexes

create the filter using the individual variables

OTHER TIPS

You can use below function to convert your date variable in yyyy-mm-dd format:

function formatDate(date) {
    var d = new Date(date),
        month = '' + (d.getMonth() + 1),
        day = '' + d.getDate(),
        year = d.getFullYear();

    if (month.length < 2) 
        month = '0' + month;
    if (day.length < 2) 
        day = '0' + day;

    return [year, month, day].join('-');
}

Usage:

alert(formatDate(new Date()));

Date before 180 days from today:

var dateObj = new Date();
dateObj.setDate(d.getDate()-18);

//Use above function to convert it in yyyy-mm-dd format
alert(formatDate(dateObj));

Reference: Format JavaScript date as yyyy-mm-dd.

Update - Using SharePoint Designer workflow:

Note that SharePoint REST API uses date is ISO Date Format for filtering.

To get the date parts in SharePoint designer workflow you need to use Extract Substring from End of String action in designer workflows.

You can set the date by subtracting 180 days from today's date and then you can extract date, month, year parts from date and build/set a workflow variable in yyyy-mm-dd format.

Check below references which will help you achieve your requirements:

  1. Sharepoint designer set variable date to string in a different format?
  2. Need to get "DATE" to format YYYYMMDD-ID, is it possible using just Workflow?
  3. Workflow actions in SharePoint Designer 2013.
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top