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

AttributeError: 'whenever.Date' object has no attribute 'strptime' #195

Closed
metaperl opened this issue Jan 5, 2025 · 2 comments
Closed

Comments

@metaperl
Copy link

metaperl commented Jan 5, 2025

My objective is is to take Date instance and render as MM/DD/YYYY but I get the error AttributeError: 'whenever.Date' object has no attribute 'strptime' with the following code:

from whenever import Date, days, Instant

_ = Date.today_in_system_tz()
print(_.strptime("%m/%d/%Y"))
@ariebovenberg
Copy link
Owner

ariebovenberg commented Jan 5, 2025

Unfortunately, there's no strftime (or strptime) method on whenever.Date instances yet. Adding a strftime-like method is on the roadmap (#174).

For now, you can do:

d = Date.today_in_system_tz()
# note the formatting codes to ensure zero-padding
print(f"{d.month:0>2}/{d.day:0>2}/{d.year:0>4}")

alternatively, you can fall back on the standard library with:

Date.today_in_system_tz().py_date().strftime("%m/%d/%Y")

@ariebovenberg
Copy link
Owner

I'll be closing this issue, since the development of customized formatting can be tracked in #174

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants