Working with date and time fields
In the Accessing data in recordsets section, we saw how to read date and time values from records. It is common to also need to perform date calculations and to convert dates between their native format and string representations. Here, we will see how to perform these kinds of operations.
Odoo provides a few useful functions to create new date and time objects.
The odoo.fields.Date
object provides these helper functions:
- The
fields.Date.today()
function returns a string with the current date in the format expected by the server, using UTC as a reference. This is adequate to compute default values. It can be used directly in a date field definition by usingdefault=fields.Date.today
. - The
fields.Date.context_today(record, timestamp=None)
function returns a string with the current date in the session's context. The time zone value is taken from the record's context. The optionaltimestamp
parameter is adatetime
object and...