Python Add Minutes to DateTime Example Tutorial

Published On: 16/09/2022 | Category: Python


Hi Guys,

This article will provide some of the most important example how to add minutes to date in python. this example will help you python add minutes to datetime example. This article will give you simple example of python add minutes to date in dataframe. This tutorial will give you simple example of python add 1 minute to date string.

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

So let's see bellow example:

Example 1: Python Add Minutes to DateTime

main.py
from datetime import datetime
from dateutil.relativedelta import relativedelta

myDateString = "2022-09-01"

myDate = datetime.strptime(myDateString, "%Y-%m-%d")

addMinutesNumber = 20;
newDate = myDate + relativedelta(minutes=addMinutesNumber)

print("Old Date :")
print(myDate)

print("New Date :")
print(newDate)
Output:
Old Date :
2022-09-01 00:00:00
New Date :
2022-09-01 00:20:00

Example 2: Python Add Minutes to Current DateTime

main.py
from datetime import datetime
from dateutil.relativedelta import relativedelta
  
myDate = datetime.today()
  
addMinutesNumber = 20;
newDate = myDate + relativedelta(minutes=addMinutesNumber)
  
print("Old Date :")
print(myDate)
  
print("New Date :")
print(newDate)
Output:
Old Date :
2022-09-16 04:13:19.232998
New Date :
2022-09-16 04:33:19.232998

It will help you....

Happy Pythonic Coding!