Adam Junior
Adam Junior

Reputation: 81

how do i strip the seconds on datetime field or make the seconds editable in odoo

here is my date field :

Date = fields.Datetime('Date', required=True, default=lambda *a : time.strftime("%Y-%m-%d"+" "+"%H:%M")
                     , readonly=True, states={'draft': [('readonly', False)]})

ive already tried to strip the seconds by set it the default value, but it didnt work

or could i make the seconds editable like the hours and the minutes in this picture : datetime image

and here is my simple xml:

<record id="datetime_form" model="ir.ui.view">
        <field name="name">datetime_form</field>
        <field name="model">datetime</field>
        <field name="arch" type="xml">
            <form string="Datetime Form">
               <field name="Date" class="oe_inline"/>
            </form>
        </field>
</record>

thanks before

Upvotes: 1

Views: 1739

Answers (1)

Adam Junior
Adam Junior

Reputation: 81

ive found the answer, so if you want to strip the seconds

here is the code :

datetime.strptime(Date, '%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M')

so by using strptime field Date will be converted to datetime, and then by using strftime field date will be converted into string, and with '%Y-%m-%d %H:%M' format the date will appeared without the seconds (but as a string not date time)

Upvotes: 1

Related Questions