Format not working as expected

,

Hi folks, I’m trying to format a date using a documentation example %tY-%tm-%td Format | Fauna Documentation but it is not working.

When I run:

Format("%tY-%tm",Now())

I see the following error:

Error: [
  {
    "position": [
      "format"
    ],
    "code": "invalid argument",
    "description": "format specifiers count must be <= arguments size"
  }
]

Hi @BrunoQuaresma,

Format() expects the number of arguments being processed to match the number of format instructions. In this case, you’ve giving two format instructions (%tY and %tm) but only a single argument to format, the sole call to Now(). Instead, you would provide two different calls to Now(), so each format instruction has its own data to work with.

Format("%tY-%tm", [Now(),Now()])

2022-01

Even though there are two calls to Now() here Fauna will use the same timestamp for any functions in a given transaction, so you don’t have to worry about getting the wrong datetimes mixed up with each other.

Cory

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.