Reputation: 611
I want to display the Date in dd/MM/yyyy format instead of dd/mm/yyyy hh:mm:ss
When I used : strftime('%Y-%m-%d')
, format doesn't change.
date = fields.Datetime('Date', default=fields.Datetime.now().strftime('%Y-%m-%d'))
Upvotes: 2
Views: 4674
Reputation: 725
Use Date() function to convert datetime.datetime
object to date
object.
like for example you have field date
which is datetime.datetime object so you can do is, fetch this fields and grab like this date.date()
.
Upvotes: 3
Reputation: 1590
Just use:
date = fields.Date(string='Date', default=fields.Date.context_today)
default=
is setting only value for new objects. It does not change its format.
Upvotes: 2
Reputation: 26678
The format used to display Date
and Datetime
fields is defined depending on the type of the widget, you can check that in the init function:
format : this.type_of_date === 'datetime' ? time.getLangDatetimeFormat() : time.getLangDateFormat()
The datetime
widget extends the date widget and defines its type to datetime
.
To force the Datetime
field to display its value using the date format, try to set the widget
attribute to date
.
<field name='date' widget='date'/>
Upvotes: 3