0

Application built with: Python and Angular

I have a form that uses the following input to allow a user to insert a date:

<input type="datetime-local" id="clubJoined" name="clubJoined" class="date-input" formControlName="clubJoined">

And in my python backend I convert this string object into a date object using the following:

#   - Club Joined
"club_joined": datetime.datetime.strptime(request.form["clubJoined"], '%y-%m-%d %H:%M')

But this gives me a formatting error:

ValueError: time data '2011-01-01T23:36' does not match format '%y-%m-%d %H:%M'

So I added the T so that the conversation format looks like this:

#   - Club Joined
"club_joined": datetime.datetime.strptime(request.form["clubJoined"], '%y-%m-%dT%H:%M')

But this gave me the following error:

ValueError: time data '2011-01-01T23:36' does not match format '%y-%m-%dT%H:%M'

How do I format this correctly?

1
  • 1
    Please see the documentation. The short answer is that %y is the format code for a two-digit year; %Y for a fully specified year. Commented Dec 16, 2021 at 23:49

1 Answer 1

1

The correct format is "%Y-%m-%dT%H:%M"

%y stands for two-digits year, here you can find full list of format options.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, that worked

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.