Odoo Help

Welcome!

This community 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.

1

How does converted string into datetime works?

By
Anirudh Lou
on 1/13/15, 9:05 PM 1,577 views

Hello to all, i just wonder why i am getting an error for my converted string into datetime.

I have these fields:

current_year  = form['year_id'][1]

date_range = datetime.strptime(str(current_year)+'-01-01','%Y-%m-%d').date()

total_month_elapsed = (book_list.date_from.year - date_range.year) * 12 + book_list.date_from.month - date_range.month

 

I don't know when date_range is read the terminal says:

    date_range = datetime.strptime(str(current_year)+'-01-01','%Y-%m-%d').date()
TypeError: must be string, not datetime.date

Any help is much appreciated.

The code as submitted seems to be fine. Maybe the problem is elsewhere. Please submit more code and also describe your issue further.

Tanveer Singh
on 1/14/15, 12:05 AM
1

Atchuthan - Technical Consultant, Sodexis Inc

--Atchuthan - Technical Consultant, Sodexis Inc--
3883
| 5 3 8
Puducherry, India
--Atchuthan - Technical Consultant, Sodexis Inc--
Passionate coder in Python/Odoo(formerly known as OpenERP).

Contact me via GMail: atchuthantu@gmail.com via Skype: atchuthan_skype
via Linkedin: http://in.linkedin.com/in/atchuthantu
Atchuthan - Technical Consultant, Sodexis Inc
On 1/14/15, 1:28 AM

To find number of months, you could use relativedelta python package

from dateutil.relativedelta import relativedelta
from datetime import date
d1 = date(2001, 5, 1)
d2 = date(2012, 1, 1)
rd = relativedelta(d2, d1)
print "{0.years} years and {0.months} months".format(rd)

Output
10 years and 8 months

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/13/15, 9:05 PM
Seen: 1577 times
Last updated: 3/16/15, 8:10 AM