How to remove seconds from datetime?

前端 未结 10 2594
终归单人心
终归单人心 2021-02-20 13:02

I have the following date and I tried the following code,

df[\'start_date_time\'] = [\"2016-05-19 08:25:00\",\"2016-05-19 16:00:00\",\"2016-05-20 07:45:00\",\"20         


        
10条回答
  •  没有蜡笔的小新
    2021-02-20 13:44

    As you mentioned removed so I assumed you don't want the seconds or microsecond in the result.If this is the case then following might help:

    datetime_variable.strftime("'%Y-%m-%d %H:%M'")

    If you have datetime in string then you can convert it in datetime obj:

    from dateutil import parser

    datetime_variable = parser.parse(str_datetime_var)

    datetime_variable.strftime("'%Y-%m-%d %H:%M'")

提交回复
热议问题