Casting dates to and from JSON


So when Appian writes dates to Json, it cannot cast those values correctly if it reads them back.

  local!jsonData: a!toJson(
  local!fromJson: cast(
    contents: {
        value: local!jsonData
        value: local!fromJson

Do I have to manually alter the string in order to reorder the date from "YYYY-MM-DDZ" to "DD-MM-YYYYZ" before I run from Json?

Is there a reason that Appian designed it this way?

  Discussion posts and replies are publicly visible

  • Hello,

    I have to say that passing the dates as integer is easier than handling it as strings.

    The drawback is that you have to cast it back to date( but that is something you are already doing as string in the code you shared)

    Hope this helps

  • Perhaps, but from what I can find the recommended way to pass dates to JSON is through the ISO 8601 standard. 

    Appian does seem to agree somewhat with this given thats how it casts dates into a JSON format, so why does it expect them to be passed in differently.

    Additionally what if this data isn't originating from the same Appian location but from an external source, I am not familiar with how Appian encodes dates to integers, is this an industry standard, so that I can ensure that the data is converted to integer in a way that Appian can reverse correctly.

    Also this fails for datetimes, so it is kind of a hack.

        label: todatetime(tointeger(now())),
        value: todatetime(tointeger(today()))

    I think that when casting to integer Appian rounds the datetime value up to the closest date value and then converts that to integer.

  • Well your concern is good, let me see if I can comment anything else on the date as string.

    For your new requirement for datetime you can use it as decimal, from which the decimal part is the time. If you cast it to integer you are truncating the decimals consequently the time.

    Regarding your concern of what happens when you move between environments or different installations. Well the decimal/integer representation uses the date 1/1/2035 00:00 GMT (Appian epoch) as the value 0. That’s why the values are negative when you cast today to integer/decimal. So you can move the values freely between Appian installation.

  • For reference, when passing date values through JSON we utilize datetext() for input and todate() for output.


    dateFrom: if(rule!APN_isEmpty(local!dateFrom),"",datetext(local!dateFrom,"MM/dd/yyyy")),
    dateTo: if(rule!APN_isEmpty(local!dateTo),"",datetext(local!dateTo,"MM/dd/yyyy"))


    local!search: a!fromJson(ri!input),
  • What if I wanted to pass a CDT into JSON?
    Would you recommend I create a parser rule to break it into a dictionary that JSON can translate properly?
Reply Children
No Data