How to Manage Date and Datetime Fields in Odoo 18
Updated on : 11 AUGUST 2025

Image Source: google.com
Table Of Contents
Introduction

Image Source: google
Date and datetime fields are essential for recording important business events in Odoo 18. They can store just the date (without time) or the complete date with a timestamp. Knowing how to handle these fields ensures accurate scheduling, reporting, and automation.
Understanding Date vs Datetime in Odoo
- Date Field → Stores only the calendar date (YYYY-MM-DD) without time information.
- Datetime Field → Stores both the date and time (YYYY-MM-DD HH:MM:SS), adjusted to the user's timezone.
Example:
2025-08-11
→ Date2025-08-11 15:30:00
→ Datetime
Defining Date and Datetime Fields in a Model
Example Python model:
from odoo import models, fields
class EventSchedule(models.Model):
_name = 'custom.event.schedule'
_description = 'Event Schedule'
event_name = fields.Char(string='Event Name')
event_date = fields.Date(string='Event Date')
event_datetime = fields.Datetime(string='Event Date & Time')
- This creates a PostgreSQL table with separate columns for date and datetime.

Need expert help managing date fields in Odoo 18? We can help.
Setting Default Values
You can set defaults using fields.Date.today()
or fields.Datetime.now():
event_date = fields.Date(string='Event Date', default=fields.Date.today)
event_datetime = fields.Datetime(string='Event Date & Time', default=fields.Datetime.now)
- This ensures records are created with the current date/time automatically.
You Might Also Like
Inserting Date/Datetime Values with XML
Example XML file:
<odoo>
<record id="event_launch" model="custom.event.schedule">
<field name="event_name">Product Launch</field>
<field name="event_date">2025-08-20</field>
<field name="event_datetime">2025-08-20 14:00:00</field>
</record>
</odoo>
- Place in data/ folder and include in manifest.py.
Using Python to Create Time-Based Records
Example Python script:
from odoo import api, SUPERUSER_ID, fields
def populate_event(env):
env['custom.event.schedule'].create({
'event_name': 'Annual Meeting',
'event_date': fields.Date.today(),
'event_datetime': fields.Datetime.now()
})
Importing Date Fields with CSV
Example CSV file:
id,event_name,event_date,event_datetime
event_webinar, Webinar on Odoo, 2025-08-25, 2025-08-25 11:00:00
event_training, Training Session, 2025-08-30, 2025-08-30 15:00:00
- Make sure the date format matches Odoo’s expectations: YYYY-MM-DD for date and YYYY-MM-DD HH:MM:SS for datetime.

Want to automate date & datetime handling in Odoo 18? Let us set it up for you.
Timezone Considerations
Timezone Considerations |
---|
Odoo stores datetimes in UTC in PostgreSQL. |
Dates remain unaffected by timezone. |
The datetime is converted to the user’s local timezone upon display. |
FAQs
Q1. What’s the difference between Date and Datetime in Odoo 18?
A: Date stores only the calendar date, while Datetime stores both date and time.
Q2. Can I store only time without a date?
A: Odoo does not have a time-only field; you can use Datetime and ignore the date part.
Q3. How do I set the default date in a model?
A: Use default=fields.Date.today for date and default=fields.Datetime.now for datetime.
Q4. How does Odoo handle timezones?
A: Datetime values are stored in UTC and displayed in the user’s local timezone.
Q5. Can I update date fields using XML?
A: Yes, use the same record ID and update the field value in XML.