Forum Discussion

DonLarson's avatar
DonLarson
Qrew Elite
2 years ago

Jinja First Day of the Month

I am trying to get a Jinja Expression to give me the First Day of the Month.   Searching the Help Section and web, the Replace function should work.

{{time.now|replace(day=1)}}

The error message I am getting is

Validation error: Incorrect template "{{time.now|replace(day=1)}}". TypeError: do_replace() got an unexpected keyword argument 'day'


There are plenty of Python references out there for this and Replace is listed in the QB Help.  I am sure it is a subtle syntax change to get the right output.




------------------------------
Don Larson
------------------------------
  • Hi Don,
    I used the following syntax instead and was able to return the first day of the current month...

    {{(time.now).replace(day=1)}}

    Let me know if that one works for you!



    ------------------------------
    Tyler Foster
    Associate Developer
    Synctivate Inc.
    ------------------------------
    • DonLarson's avatar
      DonLarson
      Qrew Elite

      Tyler,

      Perfect.  Worked like a charm.


      Just to show the syntax change.  Here is the snippet from Help where it is a Pipe to use Replace.

      Return a copy of the value with all occurrences of a substring replaced with a new one. The first argument is the substring that should be replaced, the second is the replacement string. If the optional third argument count is given, only the first count occurrences are replaced:

      {{ "Hello World"|replace("Hello", "Goodbye") }} output: Goodbye World


      Thanks again!



      ------------------------------
      Don Larson
      ------------------------------