Python Add Minutes to DateTime Example

30-Aug-2022

.

Admin

Python Add Minutes to DateTime Example

Hi Dev,

This tutorial is focused on Python Add Minutes to DateTime Example. you can understand a concept of How to Add Minutes to Date in Python?. if you want to see example of Python Add Minutes to Date in Dataframe then you are a right place. if you want to see example of Python 3 Add Minutes to Datetime String then you are a right place.

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.

so let's see following examples with output:

Example 1: Python Add 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")

addMinutesNumber = 20;

newDate = myDate + relativedelta(minutes=addMinutesNumber)

print("Old Date :")

print(myDate)

print("New Date :")

print(newDate)

Output:

Old Date :

2022-06-01 00:00:00

New Date :

2022-06-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-06-20 09:28:44.405902

New Date :

2022-06-20 09:48:44.405902

#Python