import pandas as pd
# current day
present_day = pd.to_datetime('now')
# future day (10 days later)
future_day = present_day + pd.to_timedelta(10, unit='days')
print("Present Date and time :" , present_day)
print("Future Date and time : ", future_day)
Output
Present Date and time : 2020-04-13 13:35:44.877832
Future Date and time : 2020-04-23 13:35:44.877832
import pandas as pd
# current day
present_day = pd.to_datetime('now')
# future date (add 4 months)
future_day = present_day + pd.to_timedelta(4, unit='M')
print("Present Date and time :" , present_day)
print("Future Date and time : ", future_day)
Output
Present Date and time : 2020-04-13 13:48:30.168673
Future Date and time : 2020-08-13 07:44:54.168673
import pandas as pd
# current day
present_day = pd.to_datetime('now')
# Add 4 years correctly using DateOffset
future_day = present_day + pd.DateOffset(years=4)
print("Present Date and time :" , present_day)
print("Future Date and time : ", future_day)
Output
Present Date and time : 2020-04-13 13:50:29.531906
Future Date and time : 2024-04-13 13:07:17.531906
import pandas as pd
# current day
present_day = pd.to_datetime('now')
# future date (add 2 weeks)
future_day = present_day + pd.to_timedelta(2, unit='W')
print("Present Date and time :" , present_day)
print("Future Date and time : ", future_day)
Output
Present Date and time : 2020-04-13 13:50:55.697808
Future Date and time : 2020-04-27 13:50:55.697808
import pandas as pd
# current day
present_day = pd.to_datetime('now')
# future date (add 2 hours)
future_day = present_day + pd.to_timedelta(2, unit='H')
print("Present Date and time :" , present_day)
print("Future Date and time : ", future_day)
Output
Present Date and time : 2020-04-13 13:51:58.302150
Future Date and time : 2020-04-13 15:51:58.302150
import pandas as pd
# current day
present_day = pd.to_datetime('now')
# future date (add 10 minutes)
future_day = present_day + pd.to_timedelta(10, unit='minutes')
print("Present Date and time :" , present_day)
print("Future Date and time : ", future_day)
Output
Present Date and time : 2020-04-13 13:52:47.943290
Future Date and time : 2020-04-13 14:02:47.943290
import pandas as pd
# current day
present_day = pd.to_datetime('now')
# future date (add 10 seconds)
future_day = present_day + pd.to_timedelta(10, unit='seconds')
print("Present Date and time :" , present_day)
print("Future Date and time : ", future_day)
Output
Present Date and time : 2020-04-13 13:53:34.288719
Future Date and time : 2020-04-13 13:53:44.288719
import pandas as pd
# current day
present_day = pd.to_datetime('now') # current day
# future date (add 100 milliseconds)
future_day = present_day + pd.to_timedelta(100, unit='millis')
print("Present Date and time :" , present_day)
print("Future Date and time : ", future_day)
Output
Present Date and time : 2020-04-13 13:54:26.743903
Future Date and time : 2020-04-13 13:54:26.843903
import pandas as pd
# current day
present_day = pd.to_datetime('now')
# future date (add 100 microseconds)
future_day = present_day + pd.to_timedelta(100, unit='micros')
print("Present Date and time :" , present_day)
print("Future Date and time : ", future_day)
Output
Present Date and time : 2020-04-13 13:55:07.402857
Future Date and time : 2020-04-13 13:55:07.402957
import pandas as pd
# parse present_day from custom format
present_day = pd.to_datetime('12252020:233445', format='%m%d%Y:%H%M%S')
# Add 5 years using DateOffset (handles calendar rules)
future_day = present_day + pd.DateOffset(years=5)
print("Present Date and time :", present_day)
print("Future Date and time : ", future_day)
Output
Present Date and time : 2020-12-25 23:34:45
Future Date and time : 2025-12-26 04:40:45
Adding day hour minute and secondary
import pandas as pd
# create a timedelta and add it to a datetime
dt_delta = pd.to_timedelta('1 days 5 hours 22 minute 34.006 second')
print(dt_delta)
dt_bd = pd.to_datetime('2001-11-27 16:20:05')
print(dt_bd + dt_delta)
Output
1 days 05:22:34.006000
2001-11-28 21:42:39.006000
import pandas as pd
# Create a Series of Timedelta values (0 to 5 days)
td = pd.Series([
pd.Timedelta(days=i) for i in range(6)
])
print(td)
print(td.dtypes)
Output
0 0 days
1 1 days
2 2 days
3 3 days
4 4 days
5 5 days
dtype: timedelta64[ns]
timedelta64[ns]
Pandas date & time
date_range()
period_range()
to_excel()
Author
🎥 Join me live on YouTubePassionate about coding and teaching, I publish practical tutorials on PHP, Python, JavaScript, SQL, and web development. My goal is to make learning simple, engaging, and project‑oriented with real examples and source code.