Advertisement
GamerBhai02

Datetime add subtract

Apr 3rd, 2025 (edited)
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.65 KB | Source Code | 0 0
  1. from datetime import datetime, timedelta
  2.  
  3. def pass_date(year, month, date, hour, minute, second, msecond):
  4.     return datetime(year, month, date, hour, minute, second, msecond)
  5.  
  6. year, month, date, hour, minute, second, msecond = map(int, input("Enter your date object in the format 'year month date hour minute second msecond':").split())
  7. x = pass_date(year, month, date, hour, minute, second, msecond)
  8.  
  9. print("Passed date:", x)
  10. print(x.strftime("Day is %a/%A"))
  11.  
  12. add_time = x + timedelta(days=2, hours=3, minutes=15)
  13. print("After Adding Time:", add_time)
  14.  
  15. sub_time = x - timedelta(days=4, hours=6, minutes=23)
  16. print("After Subtracting Time:", sub_time)
Tags: Datetime
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement