Forum Discussion

MattMakris's avatar
MattMakris
Qrew Cadet
2 years ago

Pipelines/Jinja: How to check if datetime field is empty or not

I'm running into an issue with an 'if' statement I'm using in a field in a Pipeline.

{% if a.$prev.client_live_date is not defined %}
  TBD
{% else %}
  {{a.$prev.client_live_date.strftime('%m/%d/%Y')}}
{% endif
%}

When the pipeline runs, it's throwing this error:
UndefinedError: 'None' has no attribute 'strftime'

Does anyone have a solution for this? Thank you.



------------------------------
Matt Makris
------------------------------

1 Reply

  • AngelRodriguez's avatar
    AngelRodriguez
    Qrew Assistant Captain

    Hi Matt,

    You can try replacing the is not defined with is None

    Here, you're checking to see if date is null, or in Python the comparison would be None.

    {% if a.$prev.client_live_date is None %}
      TBD
    {% else %}
      {{a.$prev.client_live_date.strftime('%m/%d/%Y')}}
    {% endif %}

    Let me know if that works for you.



    ------------------------------
    AR
    ------------------------------