Parsing DataTime from JSON

Certified Associate Developer

Hello,

I've noticed that the newer version of a!fromJson() parses DataTime value differently, which results in receiving a different date value than the one received. I am looking for a bullet-proof way of setting the correct timezone and receiving the original date.

For example, the integration returns DateTime value like:

"dateOfBirth":"1955-08-03T00:00:00+02:00"

When using a!fromJson(), the resulting Map gets the value:

dateOfBirth=02/08/1955 23:00

I've tried playing with local(), but the dates still get switched up if the hour values are close to midnight. The a!fromJson19_r2 still returns the correct date.

Thanks for ¨your help!

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Lead Developer

    datevalue(left(tostring(local!yourIntegrationResult.dateOfBirth), 10))
    Sample code

    a!localVariables(
      local!rawJson: "{" & char(34) & "dateOfBirth" & char(34) & ":" & char(34) & "1955-08-03T00:00:00+02:00" & char(34) & "}",
      local!parsedMap: a!fromJson(local!rawJson),
      local!wrongDate: local!parsedMap.dateOfBirth,
      local!rawDateText: left(tostring(local!parsedMap.dateOfBirth), 10),
      local!correctedDate: datevalue(local!rawDateText),
    
      {
        "Wrong Date: " & local!wrongDate,
        "Raw Text: " & local!rawDateText,
        "Correct Date: " & local!correctedDate
      }
    )

Reply
  • 0
    Certified Lead Developer

    datevalue(left(tostring(local!yourIntegrationResult.dateOfBirth), 10))
    Sample code

    a!localVariables(
      local!rawJson: "{" & char(34) & "dateOfBirth" & char(34) & ":" & char(34) & "1955-08-03T00:00:00+02:00" & char(34) & "}",
      local!parsedMap: a!fromJson(local!rawJson),
      local!wrongDate: local!parsedMap.dateOfBirth,
      local!rawDateText: left(tostring(local!parsedMap.dateOfBirth), 10),
      local!correctedDate: datevalue(local!rawDateText),
    
      {
        "Wrong Date: " & local!wrongDate,
        "Raw Text: " & local!rawDateText,
        "Correct Date: " & local!correctedDate
      }
    )

Children
No Data