Stripping off the seconds in datetime python

dtwithoutseconds = dt.replace(second=0, microsecond=0)

http://docs.python.org/library/datetime.html#datetime.datetime.replace


I know it's quite old question, but I haven't found around any really complete answer so far.

There's no need to create a datetime object first and subsequently manipulate it.

dt = datetime.now().replace(second=0, microsecond=0)

will return the desired object


You can use datetime.replace to obtain a new datetime object without the seconds and microseconds:

the_time = datetime.now()
the_time = the_time.replace(second=0, microsecond=0)