from_date = fields.Datetime(string='Start', required=True)
This field gives me: 05/08/2022 11:05:39 this type output.
But I only need Time as an output: 11:05:39
How can I do this kindly help
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
from_date = fields.Datetime(string='Start', required=True)
This field gives me: 05/08/2022 11:05:39 this type output.
But I only need Time as an output: 11:05:39
How can I do this kindly help
from datetime import datetime
datetime.strftime(from_date , "%H:%M:%S")
@ Waleed Mohsen not working brother
The above code is working with me in Odoo 15.0. Make sure to use self before the field name.
What Odoo version you are using?
What the result you are getting?
Could you please post your code?
@Waleed Mohsen brother check:
from odoo import fields, api, models
from odoo.exceptions import ValidationError
from datetime import datetime
class Regular(models.Model):
_name = 'attendance.regular'
_rec_name = 'employee_id'
_description = 'Approval Request'
_inherit = ['mail.thread', 'mail.activity.mixin']
from_date = fields.Datetime(string='Start', required=True, compute="_compute_time")
to_date = fields.Datetime(string='End')
def _compute_time(self):
for rec in self:
if rec.from_date:
rec.datetime.strftime(self.from_date, "%H:%M:%S")
For XML view :
<field name="from_date"/>
from odoo import fields, api, models
from odoo.exceptions import ValidationError
from datetime import datetime
class Regular(models.Model):
_name = 'attendance.regular'
_rec_name = 'employee_id'
_description = 'Approval Request'
_inherit = ['mail.thread', 'mail.activity.mixin']
from_date = fields.Datetime(string='Start', required=True)
from_time = fields.Char(compute="_compute_time")
to_date = fields.Datetime(string='End')
def _compute_time(self):
for rec in self:
if rec.from_date:
rec.from_time = datetime.strftime(rec.from_date, "%H:%M:%S")
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up