How To Sub Days Date In Python?
Hello Friends,
Now let's see example of how to get sub days from current date day in python. I am going to show you python date to sub days example. We will learn sub days in date using python.
The datetime module is supplies classes for manipulating dates and times. This article will give you example of how to sub days to dates in python.
Here I will give an example for how to sub days to date in python. I am use datetime and time module to sub days date. So let's see the below example:
So let's start following example.
Example : 1
example1.py
# import datetime module
from datetime import datetime,timedelta
currentTimeDate = datetime.now() - timedelta(10)
subDate = currentTimeDate.strftime('%Y-%m-%d')
print(subDate)
Run Example:
python example1.py
Output:
2021-12-13
Example : 2
example2.py
# import datetime module
from datetime import timedelta, date
currentTimeDate = date.today() - timedelta(5)
subDate = currentTimeDate.strftime('%Y-%m-%d')
print(subDate)
Run Example:
python example2.py
Output:
2021-12-18
Example : 3
example3.py
# import pandas module
import pandas as pd
my_date = "2021-12-18"
res_date = pd.to_datetime(my_date) - pd.DateOffset(days=3)
req_date = req_date.strftime('%Y-%m-%d')
print(res_date)
Run Example:
python example3.py
Output:
2021-12-15
It will help you....
- 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?