You can use datetime.replace() method -

>>> d = datetime.datetime.today().replace(microsecond=0)
>>> d
datetime.datetime(2015, 7, 18, 9, 50, 20)
Answer from Anand S Kumar on Stack Overflow
🌐
Luasoftware
code.luasoftware.com › tutorials › python › python-datetime-remove-millliseconds-and-seconds
Python Datetime Remove Millliseconds and Seconds (or time)
February 21, 2021 - python · datetime · Remove second and milliseconds · import datetimenow = datetime.datetime.now().replace(second=0, microsecond=0) Remove time · now = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) ❤️ Is this article helpful?
Discussions

How do i remove milliseconds?
Well, I don't know how your objects are structured; at worst, you could just parse the result: no_milliseconds = str(obj.duration).split(".")[0] More on reddit.com
🌐 r/learnpython
6
1
June 27, 2022
Removing milliseconds from datetime object in Python - Stack Overflow
I am trying to remove the milliseconds(28109) from this string 2017-09-12 22:33:55.28109 in Python. code: import datetime as dt from datetime import date,datetime created_date = datetime. More on stackoverflow.com
🌐 stackoverflow.com
September 20, 2017
python - Format a datetime into a string with milliseconds - Stack Overflow
How can I format a datetime object as a string with milliseconds? More on stackoverflow.com
🌐 stackoverflow.com
python - Strip microsecond from datetime - Stack Overflow
For a given timedata - 2018-06-01 06:36:40.047883+00:00, I want to remove microsecond and strip the value after '+'. Most of my dataset contains values like 2018-06-04 11:30:00+00:00 without the More on stackoverflow.com
🌐 stackoverflow.com
August 27, 2018
🌐
w3resource
w3resource.com › python-exercises › date-time-exercise › python-date-time-exercise-17.php
Python: Drop microseconds from datetime - w3resource
July 22, 2025 - It retrieves the current date and time using "datetime.datetime.today()". Then, it removes the microseconds from the time component using the "replace()" method with the argument 'microsecond=0'. Finally it prints the current date and time with ...
🌐
Finxter
blog.finxter.com › home › learn python blog › 5 best ways to remove milliseconds from python datetime
5 Best Ways to Remove Milliseconds from Python datetime - Be on the Right Side of Change
February 28, 2024 - One fundamental approach to remove milliseconds is to use the replace() method available in Python’s datetime module. This method provides a way to replace specified fields of a datetime object with new values.
🌐
Reddit
reddit.com › r/learnpython › how do i remove milliseconds?
r/learnpython on Reddit: How do i remove milliseconds?
June 27, 2022 -

In my django project i need to display duration of quiz test. In my model i have two datetime fields:

create_timestamp = models.DateTimeField(auto_now_add=True)
update_timestamp = models.DateTimeField(auto_now=True)

I've made a property method to display duration:

@property
def duration(self): 
    return self.update_timestamp - self.create_timestamp

In HTML output is like this: 0:02:09.099502

I wanna get rid of milliseconds. Please help \_o_O_/

🌐
8bitavenue
8bitavenue.com › get-current-datetime-without-milliseconds-in-python
Get current datetime without milliseconds in Python – 8 BIT AVENUE
August 11, 2018 - In Python, the datetime module can be used to get date and time. This is good but there is something annoying: the milliseconds or the fraction that gets printed by default. How can we get rid of that ?
🌐
YouTube
youtube.com › codegpt
python datetime truncate milliseconds - YouTube
Download or Run this code online using IDE at https://ide.codegive.com In Python, the datetime module provides functionalities to work with dates and times. ...
Published   December 25, 2023
Views   76
Find elsewhere
🌐
Quora
quora.com › How-can-I-delete-minutes-seconds-and-microseconds-from-a-timestamp-value-using-Python-For-example-I-have-1508265552-which-is-10-17-2017-6-39pm-I-want-to-get-1508263200-which-is-same-day-but-6-00pm
How can I delete minutes, seconds and microseconds from a timestamp value using Python? For example, I have 1508265552 which is 10/17/201...
Answer (1 of 7): Here you go. Remove the remainder from the timestamp divided by 3600 (Number of seconds in a hour) BTW the timestamp is the number of seconds from since midnight Universal Time (UTC) of January 1, 1970. No microseconds involved. $ python >>> time = 1508265552 >>> def remove_r...
🌐
CopyProgramming
copyprogramming.com › howto › python-python-datetime-datetime-now-remove-microseconds
Python datetime remove microseconds: Complete 2026 Guide with Python 3.13+ Features
December 15, 2025 - Use microsecond=dt.microsecond // 1000 * 1000 to preserve millisecond precision while zeroing the last three digits, or microsecond=0 to remove all fractional seconds. ... Python 3.13's experimental JIT compiler accelerates CPU-intensive datetime arithmetic by 10-30% in tight loops, while the ...
🌐
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
'milliseconds': Include full time, but truncate fractional second part to milliseconds. HH:MM:SS.sss format. 'microseconds': Include full time in HH:MM:SS.ffffff format. ... Excluded time components are truncated, not rounded.
🌐
CopyProgramming
copyprogramming.com › howto › remove-milliseconds-from-time-format-in-python
Remove Milliseconds from DateTime in Python: Complete Guide for 2026
November 24, 2025 - By removing milliseconds proactively in Python, you gain better control over data consistency before it reaches storage or external systems. The replace() method is the most straightforward and performant way to remove milliseconds and microseconds from a datetime object.
🌐
Brainly
brainly.com › computers and technology › high school › how do you remove microseconds from a datetime object in python?
[FREE] How do you remove microseconds from a datetime object in Python? - brainly.com
To remove microseconds from a datetime object in Python, you can replace the microsecond part with zero using the replace() method of the datetime object.
🌐
GeeksforGeeks
geeksforgeeks.org › python › remove-seconds-from-the-datetime-in-python
Remove Seconds from the Datetime in Python - GeeksforGeeks
July 23, 2025 - Example: This example uses the replace method to remove the seconds from the Datetime in Python.
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-use-strptime-with-milliseconds-in-python
How to use strptime with milliseconds in Python - GeeksforGeeks
July 23, 2025 - Here's how to do it: ... from datetime ... = datetime.strptime(s, format) print(dt_obj) ... Use %f when you want to include milliseconds or microseconds in your datetime string....
🌐
Tutorjoes
tutorjoes.in › Python_example_programs › drop_microseconds_from_datetime_in_python
Write a Python program to drop microseconds from datetime
September 24, 2022 - Convert Date to DateTime in python · Print Next Five Days Starting From Today in python · Add Seconds With Current Time in python · Convert Year Month Day to DayofYear in python · Get Current Time Milliseconds in python · Subtract Three Days From Current Date ·