Odoo Help

0

Extract time to field datetime

By
pepito
on 6/28/13, 6:04 PM 5,922 views

Would like to extract a field datetime through a method on_change the time when the field is selected datetime time.

Example:

  • datetime: 28-06-2013 17:05
  • extract: 17:05

How could I?

thanks

1
Yogesh
On 6/29/13, 5:03 AM

in on_change when you will pass a date it will be in string type. So you can perform all string operation on it directly. in other case if you get in datetime type simply convert it into string type by str(date) then you can perform string operation on it.

here you need to do this :

def on_change(self, cr, uid, ids, date):

res={}

if date:

time = date[10:]

enter your code here

return res

0

Instead of hard-coding with date[10:].

You could get the hour-minute in various formats 

http://www.cyberciti.biz/faq/howto-get-current-date-time-in-python/

import time 
print (time.strftime("%H:%M:%S"))  

## 12 hour format ##
print (time.strftime("%I:%M:%S"))

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.

Register

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

0 follower(s)

Stats

Asked: 6/28/13, 6:04 PM
Seen: 5922 times
Last updated: 3/16/15, 8:10 AM