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

Extract time to field datetime

By
pepito
on 6/28/13, 6:04 PM 4,524 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

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 7/24/14, 1:39 AM

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"))

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

0 follower(s)

Stats

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