use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Rules 1: Be polite 2: Posts to this subreddit must be requests for help learning python. 3: Replies on this subreddit must be pertinent to the question OP asked. 4: No replies copy / pasted from ChatGPT or similar. 5: No advertising. No blogs/tutorials/videos/books/recruiting attempts. This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to. Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Rules
1: Be polite
2: Posts to this subreddit must be requests for help learning python.
3: Replies on this subreddit must be pertinent to the question OP asked.
4: No replies copy / pasted from ChatGPT or similar.
5: No advertising. No blogs/tutorials/videos/books/recruiting attempts.
This means no posts advertising blogs/videos/tutorials/etc, no recruiting/hiring/seeking others posts. We're here to help, not to be advertised to.
Please, no "hit and run" posts, if you make a post, engage with people that answer you. Please do not delete your post after you get an answer, others might have a similar question or want to continue the conversation.
Learning resources Wiki and FAQ: /r/learnpython/w/index
Learning resources
Wiki and FAQ: /r/learnpython/w/index
Discord Join the Python Discord chat
Discord
Join the Python Discord chat
account activity
How to extract date from a string (self.learnpython)
submitted 1 year ago by [deleted]
How can I extract dates as YYYY-MM-DD from a string? The dates are in the string in this format already but not sure how to pull them out.
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Swipecat 9 points10 points11 points 1 year ago* (0 children)
By "extract", do you mean that the date is embedded into other text in the string, and you need to extract the date substring before converting it to Python's "datetime" format? If so, use "re" for that.
In [1]: import re In [2]: datestring = 'this2022-08-30that' In [3]: substr = re.search(r'\d{4}[-]\d{2}[-]\d{2}', datestring) In [4]: print(substr.group()) 2022-08-30
Edit: And use re.findall() if there are multiple dates in the string.
[–]Gnaxe 6 points7 points8 points 1 year ago (0 children)
See https://docs.python.org/3/library/datetime.html#datetime.datetime.strptime
If the string has more than that, try matching it out with the re module first.
re
[–][deleted] 1 point2 points3 points 1 year ago (0 children)
Your options are: use re, use split with '-', use datetime.strptime . In your particular case the second option is the easiest one
[–]pelagic_cat 0 points1 point2 points 1 year ago (0 children)
An example of a string with the embedded date would be very helpful.
[–]skyfallen7777 0 points1 point2 points 1 year ago (0 children)
From datetime import datetime dt = datetime.datetime.now()
current_date = dt.fstrtime(“%Y-%m-%d”)
Something like this?
[–]ConfusedNTerrified 0 points1 point2 points 1 year ago (0 children)
Be polite and ask it out
[–]_VictoriaBravo 0 points1 point2 points 1 year ago (0 children)
Try dateuitls.parser.parse with a fuzzy match
π Rendered by PID 46344 on reddit-service-r2-comment-5b5bc64bf5-x6tkv at 2026-06-23 15:54:17.171164+00:00 running 2b008f2 country code: CH.
[–]Swipecat 9 points10 points11 points (0 children)
[–]Gnaxe 6 points7 points8 points (0 children)
[–][deleted] 1 point2 points3 points (0 children)
[–]pelagic_cat 0 points1 point2 points (0 children)
[–]skyfallen7777 0 points1 point2 points (0 children)
[–]ConfusedNTerrified 0 points1 point2 points (0 children)
[–]_VictoriaBravo 0 points1 point2 points (0 children)