Odoo Help


How to retrieve correct date format when calculating end date?

Darius Martinkus
on 2/19/15, 7:24 AM 1,332 views

Hello odoo community,

i have a field end date which is computed (start date + duration) compute  works but for some reason my results retrieve date format like 2015-12-19 00:00:00 any ideas how to get only 2015-12-19?

Any help or examples would be appreaciated.


from openerp.osv import osv, fields
from openerp import api
import time
from datetime import date
from datetime import datetime
from dateutil.relativedelta import relativedelta


Field :

'start_date': fields.date('Start Date', required=True),
'duration': fields.integer('Duration', required=True, help='Estimated project duration in months', store=True),

'end_date': 'fields.char(compute='_end_date', string='End Date', help='Calculated as start date plus duration in months'),

    _defaults = {
        'start_date': fields.date.context_today,

compute function:

    def _end_date(self):
        self.end_date = datetime.strptime(self.start_date, '%Y-%m-%d') + relativedelta(months=self.duration)


Thank you

It worked Thanks!!!

Darius Martinkus
on 2/19/15, 7:36 AM
Jordan Vrtanoski
On 2/19/15, 7:29 AM

Convert the date to string with explicit format like in the example below

 def _end_date(self):
        self.end_date = (datetime.strptime(self.start_date, '%Y-%m-%d') + relativedelta(months=self.duration)).strftime('%Y-%m-%d')

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 2/19/15, 7:24 AM
Seen: 1332 times
Last updated: 10/23/15, 9:29 AM