Forum Discussion

VictorC's avatar
VictorC
New Contributor
5 years ago

Problems with Date.parse() function

Hi, I have a problem with the Date.parse () function.
I cannot convert a String to date, the format of my string is the following: “dd/MM/yyyy”.
It only happens to me with some specific dates (with most data I have no problem).
The problem occurs with the following examples:
Date.parse (“01/04/1932”, “dd/MM/yyyy”)
Date.parse (“05/02/1939”, “dd/MM/yyyy”)
Date.parse (“09/12/1940”, “dd/MM/yyyy”)
Date.parse (“16/12/1943”, “dd/MM/yyyy”)
Date.parse (“12/02/1950”, “dd/MM/yyyy”)
And I always get a NaN as a result of the function.
Thank you.

10 Replies

  • Victor,
    I can understand how 16/12/1943 would fail. But I tested 1932, 1940 and 1950 and had no issues
    This in the mapper expression
    Date.parse (“09/12/1940”,“dd/MM/yyyy”)
    this is the result
    _snaptype_datetime: “1940-12-09T00:00:00.000 UTC”

    please try again

    • petar_rajchinos's avatar
      petar_rajchinos
      New Contributor III

      Hi @rdill,

      I have quite similar problem while using Date.parse() function. (Sound to me that started after the new release)

      I have a mapper and an input value that I’m trying to parse using Date.parse(). On the dynamic preview it is showing the correct output but when on the real output it is writing NaN instead of the date value.
      Dynamic preview:

      JSON output of the same snap (same field):

  • VictorC's avatar
    VictorC
    New Contributor

    Hi.
    I just tried again and got the following results.

    • dmiller's avatar
      dmiller
      Former Employee

      @VictorC I’ve tried the same expressions and am not seeing the same thing.
      What are the other settings in the Snap?
      Is this validating on a Cloudplex or a Groundplex? Which version is the Snaplex on?

  • davidm's avatar
    davidm
    New Contributor

    I have a similar issue. When I use literal string, it works. But using a field, it does not. Additionally, it only happened yesterday 2021-03-14.

    This fails.

    This works.

  • davidm's avatar
    davidm
    New Contributor

    Date.parse(“2021-03-14 02:40:18.000”,“yyyy-MM-dd HH:mm:ss.SSS”)

    Use this on my mapper and it worked. However, when I use same approach on my existing snaplogic job coming from a field and it fails. I will just do date manipulation inside SQL as standard functions in Snaplogic is buggy.

    • tlikarish's avatar
      tlikarish
      Employee

      When you have time, could you give an example of the string format and date where it fails?

  • davidm's avatar
    davidm
    New Contributor

    Sure. It is actually the same date in my reply. It only fails because it returns NaN. The weird about it is that I have a similar job running the same way and it does not fail.

    Date.parse(“2021-03-14 02:40:18.000”,“yyyy-MM-dd HH:mm:ss”+“.000”) - the difference is the .000 at the end.