Forum Discussion

AConner's avatar
AConner
New Contributor
7 years ago
Solved

How to send last months date in JSON reqest while doing a HTTP Post.

I saw how to add today's date dynamically into the json payload, now I want to take tat one step further and dynamically add todays date minus 30 days into the payload.  here is the example that I have created so far I now want to set the initiationDateFrom dynamically:

 

{
  "page": 0,
  "recordsPerPage": 10,
  "find": {
    "initiationDateFrom": "4/8/2018",
    "initiationDateTo": "${= StatementDate = Calendar.instance; StatementDate.format('MM/dd/yyyy')}"
  },
  "sort": {
    "initiationDate": -1
  }
}

  • Hi,

     

    That's quite simple:

     

    {
      "page": 0,
      "recordsPerPage": 10,
      "find": {
        "initiationDateFrom": "${= StatementDate = Calendar.getInstance(); StatementDate.add(Calendar.DAY_OF_MONTH, -30); StatementDate.format('MM/dd/yyyy')}",
        "initiationDateTo": "${= StatementDate = Calendar.instance; StatementDate.format('MM/dd/yyyy')}"
      },
      "sort": {
        "initiationDate": -1
      }
    }

    You can refer to https://docs.oracle.com/javase/6/docs/api/java/util/Calendar.html#add(int,%20int) for more information. :smileyhappy:

     

    Let me know if it works!

2 Replies

  • Lucian's avatar
    Lucian
    Community Hero

    Hi,

     

    That's quite simple:

     

    {
      "page": 0,
      "recordsPerPage": 10,
      "find": {
        "initiationDateFrom": "${= StatementDate = Calendar.getInstance(); StatementDate.add(Calendar.DAY_OF_MONTH, -30); StatementDate.format('MM/dd/yyyy')}",
        "initiationDateTo": "${= StatementDate = Calendar.instance; StatementDate.format('MM/dd/yyyy')}"
      },
      "sort": {
        "initiationDate": -1
      }
    }

    You can refer to https://docs.oracle.com/javase/6/docs/api/java/util/Calendar.html#add(int,%20int) for more information. :smileyhappy:

     

    Let me know if it works!