Reputation: 11
I want a time in the below-mentioned format, using Python.
Tue, 08 Nov 2022 15:35:20 GMT
n
number of days).Any help would be highly appreciated.
I have tried the below code but not getting the desired results:
start_date = str(datetime.now()).split(".")[0]
due_date = str((datetime.now() + timedelta(days=2))).split(".")[0]
Output:
2022-11-08 23:45:15
2022-11-10 23:45:15
Upvotes: 0
Views: 57
Reputation: 50
You can try to use the below functions:
from datetime import datetime, timedelta
def get_now():
return datetime.now().strftime('%a, %d %b %Y %H:%M:%S GMT')
def n_days_from_now(n):
now = get_now()
return (datetime.now() + timedelta(days = n)).strftime('%a, %d %b %Y %H:%M:%S GMT')
Upvotes: -1