Home > Software engineering >  Python datetime.timedelta not working with in arg
Python datetime.timedelta not working with in arg

Time:09-28

I'm a complete beginner with python so sorry for my noobiness

Some background: I'm trying to do a web scraper with selenium which will run as a AWS lambda function every week to book a time slot for me to go and play some tennis. My booking site is releasing new bookable time slots at midnight 2 weeks ahead of time. I have a lambda function that will run every Wednesday at midnight.

My issue is actually when I'm using datetime.timedelta(days=14) I get a compiler error for the inarg days. screenshot

    bookingTime = nowInUtc   timedelta(days=14)

I have seen multiple examples of this syntax:

Python: Adding 3 weeks to any date

Adding days to a date in Python

What am I missing?

Im using Jetbrainz PyCharm Idea Python 3.9.7

my imports

from datetime import datetime, timedelta
import pytz

CodePudding user response:

This code works and gets the date two weeks from now. If you want to know why you code doesn't work, you'll have to post your code :)

from datetime import datetime, timedelta

now = datetime.now()
in_two_weeks = now   timedelta(days=14)
print(in_two_weeks)
  • Related