Format date and time

I need to format date and time in Print Formats. I use frappe.utils.now() but I got something like 2016-04-04 15:47:33.217346 wich is not what I want.
How can I format date and time depending on user’s locale?

@emakis use doc.get_formatted('fieldname')

3 Likes

Hi @max_morais_dmm,

I don’t need a ‘fieldname’ I just need the current date and current time, at the moment the user prints the doctype… I also tried doc.formatted(frappe.utils.now()) but didn’t work.
Any other suggestion?

1 Like

@emakis

If you want current date and current time using frappe.utils.now()

you have to split Date and Time using jinja template. Try below script

{% set date = frappe.utils.now().split(' ')[0] %} 
{% set time = frappe.utils.now().split(' ')[1] %}
Date = {{ date }} <br />
Time = {{ time }}
2 Likes

@emakis, is a bit more complex, by the way is:

{{ frappe.format_value(frappe.utils.now(), {'fieldtype': 'Date'}) }}
8 Likes