Forum Discussion

vaidyarm's avatar
vaidyarm
Contributor
6 years ago

Converting string into date and applying transformation failing

I am passing a timestamp as a variable through pipeline parameter as ‘p_querystring_modifieddateafter’.

while applying logic as below in mapper and in REST GET snap parameters, I am getting the failure :

Logic in Mapper :
_p_querystring_modifieddateafter.minusDays(1).toLocaleDateString()+“T00:00:00.000”

tried with below logic also, still failing,

LocalDateTime.parse(_p_querystring_modifieddateafter).minusDays(1).toLocaleDateString()+“T00:00:00.000”

let me know if i am making any mistake…

6 Replies

  • tstack's avatar
    tstack
    Former Employee

    Can you give an example of one of these timestamps? It looks like LocalDateTime.parse() is not parsing it correctly and returning a NaN. Also, is there are reason you’re using LocalDateTime.parse() instead of Date.parse()? Note that LocalDateTime objects do not have the date math methods like minusDays().

  • Ex :
    2019-08-09T06:51:07.000

    this need to be converted like : 2019-08-08T00:00:00.000

    • cjhoward18's avatar
      cjhoward18
      Employee

      This expression:
      Date.parse(“2019-08-09T06:51:07.000”).minusDays(1).toLocaleDateString()+“T00:00:00.000”

      results in: 2019-08-08T00:00:00.000

      Note the only change in the expression from your original one is the use of Date.parse() instead of LocalDateTime.parse()

  • for this logic :
    Date.parse(“2019-08-09T06:51:07.000”).minusDays(1).toLocaleDateString()+“T00:00:00.000”

    error :
    Could not compile expression: Date.parse(“2019-08-09T06:51:0 … (Reason: Invalid token: ‘“’ for expression: Date.parse(“2019-08-09T06:51:0 …; Resolution: Please check expression syntax)

    attached are screenshots.

    • cjhoward18's avatar
      cjhoward18
      Employee

      @vaidyarm

      The quotes you have copied and pasted into the mapper are invalid quote characters.

      Please delete the quotes and retype them in the mapper and the expression will work as expected.

  • Got the issue…
    it was “ causing the issue, where it should be "

    thanks for your great help and follow up @cjhoward18 .