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.

0

How to add 5 hrs time to a datetime field

By
scot77844
on 1/27/15, 1:38 AM 895 views

Hi,

I have a datetime field named field_date1 in which I am selecting the date. I am having another field in which I should display a datetime which is 5 hours more than the seleccted time in field_date1. I defined an onchange function and in that I wrote the following line for doing the calculation.

date_field2 = date_field1 + timedelta(0,0,0,0,0,5,0)

As timedleta takes the parameters: timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])

But I am facing an error with that. Can anyone help me with a solution.

0
Gaurav Sahu
On 1/27/15, 1:47 AM

Try This
 

DATETIME_FORMAT = "%Y-%m-%d %H:%M:%S"
date_field1 = datetime.strptime(date_field1, DATETIME_FORMAT)

date_field2 = datetime.strptime(date_field2, DATETIME_FORMAT)

date_field2 = date_field1 + timedelta(hours=5,minutes=30)

 

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

2 follower(s)

Stats

Asked: 1/27/15, 1:38 AM
Seen: 895 times
Last updated: 3/16/15, 8:10 AM