Python Add Minutes to DateTime Example
Aug 30, 2022
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
- Get Last 2 Digits of Number in Python Tutorial Example
- How to Sum of First and Last Digit of Number in Python?
- How to Get First and Last Digit of Number in Python?
- Get the Last Digit of Number in Python Tutorial Example
- Get the First Digit of Number in Python Tutorial Example
- How to Remove All Decimals from Number in Python?
- How to Convert String to Float with 2 Decimal Places in Python?
- How to Format Number to 2 Decimal Places in Python?