Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GH-124549: Add a note that when over-specifying datetime format, only the last directive gets used. #125009

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Mariatta
Copy link
Member

@Mariatta Mariatta commented Oct 5, 2024

@bedevere-app bedevere-app bot added docs Documentation in the Doc dir skip news awaiting core review labels Oct 5, 2024
@Mariatta Mariatta changed the title gh-123549: Add a note that when over-specifying datetime format, only the last directive gets used. GH-124549: Add a note that when over-specifying datetime format, only the last directive gets used. Oct 5, 2024
@Mariatta Mariatta added 3.12 bugs and security fixes 3.13 bugs and security fixes labels Oct 5, 2024
@alliesw
Copy link

alliesw commented Dec 17, 2024

from datetime import datetime

input_str = "200099"

Manually split the string

full_year = input_str[:4] # First 4 characters represent the full year
short_year = input_str[4:] # Last 2 characters represent the short year

Parse separately

date_full = datetime.strptime(full_year, "%Y")
date_short = datetime.strptime(short_year, "%y")

Now, handle both years according to your requirements

print(date_full) # Output: 2000-01-01 00:00:00
print(date_short) # Output: 1999-01-01 00:00:00

Here I'm just separately parsing both parts of the year and then I guess you apply them as needed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes awaiting core review docs Documentation in the Doc dir skip news
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

2 participants