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
🌐
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.
Discussions

simple way to drop milliseconds from python datetime.datetime object - Stack Overflow
My colleague needs me to drop the milliseconds from my python timestamp objects in order to comply with the old POSIX (IEEE Std 1003.1-1988) standard. The tortured route that accomplishes this task... More on stackoverflow.com
🌐 stackoverflow.com
Python datetime to string without microsecond component - Stack Overflow
I'm adding UTC time strings to Bitbucket API responses that currently only contain Amsterdam (!) time strings. For consistency with the UTC time strings returned elsewhere, the desired format is 20... More on stackoverflow.com
🌐 stackoverflow.com
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
python - datetime: Round/trim number of digits in microseconds - Stack Overflow
When microseconds is at least 999500, this truncates instead of rounding up. You can fix this after defining f: if f >= 1.0: return (t + datetime.timedelta(milliseconds=1)).strftime('%Y-%m-%d %H:%M:%S.000') (and otherwise continue as before). 2017-04-13T17:23:47.99Z+00:00 ... This is really nice but be aware that it is not rounding the last digit but truncating it! At least in Python ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
GeeksforGeeks
geeksforgeeks.org › python › remove-seconds-from-the-datetime-in-python
Remove Seconds from the Datetime in Python - GeeksforGeeks
July 23, 2025 - from datetime import datetime # Original datetime dt = datetime.now() print("Original datetime:", dt) # set seconds and microseconds to zero dt_truncated = dt.replace(second=0, microsecond=0) print("Truncated datetime:", dt_truncated) ... In this approach we will use string formatting, it allows us to convert a datetime object to a string in a specific format. By using the strftime method with a format string that excludes seconds ('%Y-%m-%d %H:%M') we can create a formatted string without seconds. formatted_datetime = original_datetime.strftime('%Y-%m-%d %H:%M')
🌐
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?
🌐
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_/

Find elsewhere
🌐
Python documentation
docs.python.org › 3 › library › datetime.html
datetime — Basic date and time types
The following example illustrates how any arguments besides days, seconds and microseconds are “merged” and normalized into those three resulting attributes: >>> import datetime as dt >>> delta = dt.timedelta( ... days=50, ... seconds=27, ... microseconds=10, ...
🌐
Iditect
iditect.com › faq › python › python-datetime-roundtrim-number-of-digits-in-microseconds.html
Python datetime: Round/trim number of digits in microseconds
In Python's datetime module, you can round or trim the number of digits in microseconds by manipulating the microsecond attribute of a datetime object. You can do this using the round function from the datetime module or by using basic arithmetic operations.
🌐
Homedutech
homedutech.com › program-example › python--datetime-roundtrim-number-of-digits-in-microseconds.html
python - datetime: Round/trim number of digits in microseconds
Description: The trim_microseconds function trims the microseconds of a datetime object dt to the specified number of digits. Python datetime: Round microseconds to nearest second Description: Round microseconds of a datetime object to the nearest second.
🌐
Tutorjoes
tutorjoes.in › Python_example_programs › drop_microseconds_from_datetime_in_python
Write a Python program to drop microseconds from datetime
September 24, 2022 - import datetime dt = datetime.datetime.today().replace(microsecond=0) print(dt) 2022-09-24 12:38:42 · Previous · Next · Get First And Last Second in python · Generate RFC 3339 Timestamp in python · Validate Gregorian Date in python · Drop Microseconds From Datetime in python ·
🌐
DNMTechs
dnmtechs.com › rounding-and-trimming-microseconds-in-python-3-programming
Rounding and Trimming Microseconds in Python 3 Programming – DNMTechs – Sharing and Storing Technology Knowledge
We divide the microseconds by 1000000 to convert it to seconds, round the seconds using the round() function, and then convert it back to microseconds by multiplying it with 1000000. Finally, we use the replace() method to create a new datetime object with the rounded microseconds.
🌐
Alexwlchan
alexwlchan.net › notes › 2025 › remove-microsecond-precision-in-python
Remove the microsecond precision from a datetime in Python – alexwlchan
October 19, 2025 - If you print the current date as an ISO timestamp in Python, by default it includes microsecond precision (in this case, .499258): >>> d = datetime.now() >>> d.isoformat() '2025-10-19T09:23:04.384593'
🌐
Python.org
discuss.python.org › ideas
Add builtin method to truncate a datetime object to a timedelta value - Ideas - Discussions on Python.org
November 28, 2023 - This may be the case for tools such as Apache Airflow (which trigger jobs every N minutes or hours), or Apache Spark which will probably partition your data according to a usual year=YYYY/month=MM/day=DD ...