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



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

2 Answers 2


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('-');


alert(formatDate(new Date()));

Date before 180 days from today:

var dateObj = new Date();

//Use above function to convert it in yyyy-mm-dd format

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.
  • Thanks Ganesh. After seeing your solution. I just forgot that my scenario is inside a SharePoint Desginer Workflow. I now edited my original question. Commented Oct 25, 2019 at 11:03
  • Then you need to add more details to your question. Which version of SharePoint you are using? Which version of designer workflow you are using? :) Commented Oct 25, 2019 at 11:11
  • 2013 Designer. on Online O365 Commented Oct 25, 2019 at 11:16
  • See updated answer. Please upvote and accept it as an answer if it helps you. As you are using O365, you can also look for using Microsoft flow as a replacement for designer workflow. Commented Oct 25, 2019 at 11:33
  • Please Accept it as an answer if it helped you to get the solution for your question. Commented Oct 25, 2019 at 12:52

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.