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
Remove milliseconds from date
I am building a connector which requires the date in the API call, however it needs to be format YYYY-MM-DDTHH:MM:SSZ. today = new Date(); provides the date however it also includes milliseconds. How can I get the date without milliseconds or remove them after getting the date? More on community-forums.domo.com
🌐 community-forums.domo.com
May 17, 2024
pandas - How to get rid of milliseconds for datetime in Python - Stack Overflow
I have my DateTime like this 0 2021-02-01 00:01:02.327 1 2021-02-01 00:01:21.445 2 2021-02-01 00:01:31.912 3 2021-02-01 00:01:32.600 4 2021-02-01 00:02:08.920 However... More on stackoverflow.com
🌐 stackoverflow.com
🌐
w3resource
w3resource.com › python-exercises › date-time-exercise › python-date-time-exercise-17.php
Python: Drop microseconds from datetime - w3resource
July 22, 2025 - ... # Import the datetime module import datetime # Get the current date and time, then remove the microseconds from the time component dt = datetime.datetime.today().replace(microsecond=0) # Print an empty line print() # Print the current date ...
🌐
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_/

🌐
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 - This code snippet creates a datetime object with specified year, month, day, hour, minute, second, and microsecond values, and then creates a new datetime object with the microseconds set to zero by using the replace() method.
🌐
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 ?
🌐
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.
Find elsewhere
🌐
Python Forum
python-forum.io › thread-39297.html
[SOLVED] Epoch timestamp without milliseconds?
Hello, What's a good way to get an Epoch timestamp without the milliseconds? for row in cur.execute('SELECT id,created,title FROM content'): #2004-08-18 19:11:13 formated_date = datetime.strptime(row['created'],'%Y-%m-%d %H:%M:%S') epoch = date...
🌐
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.
🌐
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
🌐
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...
Python 2.6 added a new strftime/strptime macro %f. The docs are a bit misleading as they only mention microseconds, but %f actually parses any decimal fraction of seconds with up to 6 digits, meaning it also works for milliseconds or even centiseconds or deciseconds. time.strptime('30/03/09 16:31:32.123', '%d/%m/%y %H:%M:%S.%f') However, time.struct_time doesn't actually store milliseconds/microseconds. You're better off using datetime, like this:
🌐
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 use the replace() method, setting the microsecond parameter to 0. This creates a new datetime object without microseconds.
🌐
Alexwlchan
alexwlchan.net › notes › 2025 › remove-microsecond-precision-in-python
Remove the microsecond precision from a datetime in Python – alexwlchan
October 19, 2025 - Call datetime.replace(microsecond=0) · If you print the current date as an ISO timestamp in Python, by default it includes microsecond precision (in this case, .499258):
🌐
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 ·
🌐
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 - This approach preserves the datetime ... a new instance rather than modifying the original. For partial microsecond removal (milliseconds only), use microsecond=now.microsecond // 1000 * 1000 to zero out the last three digits while preserving millisecond precision...
🌐
Printable Online
tupuy.com › home
Remove Seconds And Milliseconds From Datetime Python - Printable Online
Timestamp is the pandas equivalent ... how to transform milliseconds to a date and time object For this task we can apply the fromtimestamp function as shown below my datetime datetime datetime fromtimestamp my ms 1000 Apply ...