1

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'))
soMario
  • 22,501
  • 7
  • 19
  • 38
Ing
  • 405
  • 2
  • 8
  • Of course, you only change the default. Try changing `fields.Datetime` to `fields.Date` – DeepSpace Aug 15 '20 at 20:33
  • Sorry, I would have used a comment if I could. – xdou Aug 15 '20 at 20:41
  • 1
    You want to change the date format for one field? And if you dont want the time we declare it as datetime field?!! Could you explain what are you doing exacly – Charif DZ Aug 15 '20 at 23:06

3 Answers3

2

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'/>
Kenly
  • 16,220
  • 5
  • 36
  • 52
2

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().

Saumil gauswami
  • 462
  • 1
  • 10
1

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.

Catalina Chircu
  • 1,451
  • 2
  • 4
  • 15
Paxmees
  • 1,086
  • 1
  • 11
  • 25