How to set the date in print format

In the print format how can i set the format as Date.Month.Year - DD.MM.YYYY.
and how to block the previous date.

1 Like

Checkout strftime for date formatting in python

1 Like

It’s not working…it thrown error. Any examples?

{{ doc.posting_date.strftime('%d %b %Y') }}

Tks

1 Like

@Jonathan_Fanny_Lie what error?

It thrown below error:

Traceback (innermost last):
  File "/home/vef/frappe-bench/apps/frappe/frappe/app.py", line 51, in application
    response = frappe.handler.handle()
  File "/home/vef/frappe-bench/apps/frappe/frappe/handler.py", line 69, in handle
    execute_cmd(cmd)
  File "/home/vef/frappe-bench/apps/frappe/frappe/handler.py", line 92, in execute_cmd
    ret = frappe.call(method, **frappe.form_dict)
  File "/home/vef/frappe-bench/apps/frappe/frappe/__init__.py", line 751, in call
    return fn(*args, **newargs)
  File "/home/vef/frappe-bench/apps/frappe/frappe/templates/pages/print.py", line 107, in get_html
    html = template.render(args, filters={"len": len})
  File "/home/vef/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
    return self.environment.handle_exception(exc_info, True)
  File "/home/vef/frappe-bench/env/local/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
    reraise(exc_type, exc_value, tb)
  File "

Share your full trace from the console.

It’s full error message shown on the screen (print-view). Where can I get the full trace you’re referring?

If you are in developer mode, check your bench console.

Here the trace:

23:30:15 web.1         | Traceback (innermost last):
23:30:15 web.1         |   File "/home/ubuntu/frappe-forms/frappe-forms/apps/frappe/frappe/app.py", line 51, in application
23:30:15 web.1         |     response = frappe.handler.handle()
23:30:15 web.1         |   File "/home/ubuntu/frappe-forms/frappe-forms/apps/frappe/frappe/handler.py", line 69, in handle
23:30:15 web.1         |     execute_cmd(cmd)
23:30:15 web.1         |   File "/home/ubuntu/frappe-forms/frappe-forms/apps/frappe/frappe/handler.py", line 92, in execute_cmd
23:30:15 web.1         |     ret = frappe.call(method, **frappe.form_dict)
23:30:15 web.1         |   File "/home/ubuntu/frappe-forms/frappe-forms/apps/frappe/frappe/__init__.py", line 751, in call
23:30:15 web.1         |     return fn(*args, **newargs)
23:30:15 web.1         |   File "/home/ubuntu/frappe-forms/frappe-forms/apps/frappe/frappe/templates/pages/print.py", line 115, in get_html_and_style
23:30:15 web.1         |     no_letterhead=no_letterhead, trigger_print=trigger_print),
23:30:15 web.1         |   File "/home/ubuntu/frappe-forms/frappe-forms/apps/frappe/frappe/templates/pages/print.py", line 106, in get_html
23:30:15 web.1         |     html = template.render(args, filters={"len": len})
23:30:15 web.1         |   File "/home/ubuntu/frappe-forms/frappe-forms/env/local/lib/python2.7/site-packages/jinja2/environment.py", line 969, in render
23:30:15 web.1         |     return self.environment.handle_exception(exc_info, True)
23:30:15 web.1         |   File "/home/ubuntu/frappe-forms/frappe-forms/env/local/lib/python2.7/site-packages/jinja2/environment.py", line 742, in handle_exception
23:30:15 web.1         |     reraise(exc_type, exc_value, tb)
23:30:15 web.1         |   File "<template>", line 77, in top-level template code
23:30:15 web.1         |  UndefinedError: 'unicode object' has no attribute 'strftime'

I think the real error is that date is an unicode object and not a string object, so, there
is another way to format date?

in my case the code is:

{{ doc.transaction_date.strftime('%d %b %Y') }}

Thx!

You can get all frappe.utils try

frappe.utils.get_datetime(doc.transaction_date).strftime(...)
9 Likes

Use {{doc.get_formatted(“transaction_date”, doc)}} for Print Format