How to remove seconds from datetime?

前端 未结 10 1944
终归单人心
终归单人心 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:54

    You can subtract the seconds using a timedelta:

    import datetime    
    d = datetime.datetime.now() #datetime including seconds
    without_seconds = d - datetime.timedelta(seconds=d.second)
    

提交回复
热议问题