ItSolutionStuff.com

Python Subtract Minutes from DateTime Example

By Hardik Savani โ€ข October 30, 2023
Python

Now, let's see article of python subtract minutes to datetime example. Iรขโ‚ฌโ„ขm going to show you about how to subtract minutes to date in python. it's simple example of how to subtract minute to current date in python. This post will give you simple example of python minus minutes to date in dataframe. Let's see bellow example python subtract 1 minute to date string.

In this example, I will give two examples for you of how to subtract minutes to date in python and how to subtract minutes to today's datetime in python. therefore, let's see below example code and try it.

You can use these examples with python3 (Python 3) version.

Example 1: Python Subtract Minutes to DateTime

main.py

from datetime import datetime
from dateutil.relativedelta import relativedelta
  
myDateString = "2022-06-01"
  
myDate = datetime.strptime(myDateString, "%Y-%m-%d")
  
subMinutesNumber = 20;
newDate = myDate - relativedelta(minutes=subMinutesNumber)
  
print("Old Date :")
print(myDate)
  
print("New Date :")
print(newDate)

Output:

Old Date :
2022-06-01 00:00:00
New Date :
2022-05-31 23:40:00

Example 2: Python Subtract Minutes to Current DateTime

main.py

from datetime import datetime
from dateutil.relativedelta import relativedelta
  
myDate = datetime.today()
  
subMinutesNumber = 20;
newDate = myDate - relativedelta(minutes=subMinutesNumber)
  
print("Old Date :")
print(myDate)
  
print("New Date :")
print(newDate)

Output:

	
Old Date :
2022-06-21 09:29:18.658343
New Date :
2022-06-21 09:09:18.658343

I hope it can help you...

Tags: Python
Hardik Savani

Hardik Savani

I'm a full-stack developer, entrepreneur, and founder of ItSolutionStuff.com. Passionate about PHP, Laravel, JavaScript, and helping developers grow.

๐Ÿ“บ Subscribe on YouTube

We Are Recommending You

โ˜…

Python POST Request with Parameters Example

Read Now โ†’
โ˜…

Python GET Request with Parameters Example

Read Now โ†’
โ˜…

Python Subtract Hours from Datetime Example

Read Now โ†’
โ˜…

How to Add Hours to Date in Python?

Read Now โ†’
โ˜…

How to Subtract Year to Date in Python?

Read Now โ†’
โ˜…

How to Add Years to Date in Python?

Read Now โ†’
โ˜…

How to Subtract Months to Date in Python?

Read Now โ†’
โ˜…

How to Add Months to Date in Python?

Read Now โ†’
โ˜…

How to Subtract Days from Date in Python?

Read Now โ†’
โ˜…

How to Add Days to Date in Python?

Read Now โ†’
โ˜…

How to Get Current Date and Time in Python?

Read Now โ†’