Skip to Content
Menu
This question has been flagged
1 Reply
14324 Views

Hello, I'm running python shell in the terminal with odoo and

I created a field like:

>>> from odoo import fields
>>> dateTest = fields.Date(default=fields.Datetime.now)

and then I do:

>>> type(dateTest)

and the result is:

>>> <class 'odoo.fields.Date'>

so I want to convert this value to a string or datetime.datetime so I can use the strptime command with this variable.

And when the conversion is done, if I do >>>type(dateTest)

The result should be either ">>> <type 'str'> or >>> <type 'datetime.datetime'>, depending on the conversion done.



Thank you very much.

Avatar
Discard
Best Answer

There are lot of ways to treat datetime functions.

you can use strftime() function to convert datetime object to string.

eg:

date_obj.strftime(format_of_date)

strftime() function actually returns string representing datetime format.

or you can use the to_string(value) function from datetime

eg:

value = fields.Datetime.to_string(value)




Avatar
Discard