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 to add time difference on datetime object in Email Template ?

By
HappyOdoo
on 1/18/16, 2:51 AM 713 views

Is it possible to change datetime in Email Template?  

Example:
${object.date_start} here time is coming 2015-04-13 12:00:41 .
i want to add time difference +05:30 then which should come as 2015-04-13 17:30:41. 
object is used for Email Template.

2015-04-13 12:52:41

1
Nilesh Sheliya
On 1/18/16, 4:33 AM

yes, It is possible to change datetime in email template. Please use the below code sample in your email template. It will work.

${(datetime.datetime.strptime(object.date_start,'%Y-%m-%d %H:%M:%S') + relativedelta(hours=5,minutes=30)).strftime('%Y-%m-%d %H:%M:%S')} 


Above code will add +05:30 in date_start datetime.

0
Sandeep Sarode
On 3/18/16, 11:04 AM

Hey Nilesh,

Thanks much. This really worked for me. I just replaced the body_html code at four places in the meeting invite email template, with your code and it works great.

Existing code:

${object.event_id.get_interval(object.event_id.start, 'dayname', tz=object.partner_id.tz)}

Replaced with your sample code:

${object.event_id.get_interval(((datetime.datetime.strptime(object.event_id.start,'%Y-%m-%d %H:%M:%S') + relativedelta(hours=5,minutes=30)).strftime('%Y-%m-%d %H:%M:%S')), 'dayname', tz=object.partner_id.tz)}


Basically replace "object.event_id.start" with 

"((datetime.datetime.strptime(object.event_id.start,'%Y-%m-%d %H:%M:%S') + relativedelta(hours=5,minutes=30)).strftime('%Y-%m-%d %H:%M:%S'))"

First instance is for 'dayname', the other is for 'day', next for 'month' and finally 'time'.

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/18/16, 2:51 AM
Seen: 713 times
Last updated: 3/21/16, 5:02 AM