Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8644741
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:22:28+00:00 2026-06-12T12:22:28+00:00

I’m trying to parse a free form date string into a meaningful date. So

  • 0

I’m trying to parse a free form date string into a meaningful date. So far I’ve come up with this function:

"""Parse raw date string into YYYY-MM-DD"""
def __parseDate(self, rawDate):
    if len(rawDate) == 0:
        return u""
    if "{{Birth year and age|" in rawDate:
        rawDate = rawDate.replace("{{","").replace("}}","")
        year = rawDate.split("|")[1].strip()
        return year + "-01-01"
    elif "{{Birth date and age|" in rawDate:
        rawDate = rawDate.replace("{{","").replace("}}","")
        year = rawDate.split("|")[1].strip()
        month = rawDate.split("|")[2].strip()
        day = rawDate.split("|")[3].strip()
        if len(month) == 1:
            month = "0" + month
        if len(day) == 1:
            day = "0" + day
        return year + "-" + month + "-" + day
    elif "{{" in rawDate:
        self.__log(u"XXX Date parse error (unknown template): " + rawDate)
        return u"1770-01-01"
    elif re.match("([a-zA-Z]* [0-9][0-9]?, [0-9][0-9][0-9][0-9])", rawDate):
        match = re.findall("([a-zA-Z]* [0-9][0-9]?, [0-9][0-9][0-9][0-9])", rawDate)[0]
        parts = match.replace(",","").split(" ")
        year = parts[2].strip()
        month = parts[0].replace(".","").strip()
        day = parts[1].strip()
        tryAgain = False
        try:
            month = str(strptime(month,'%B').tm_mon)
        except:
            tryAgain = True
            pass
        try:
            if tryAgain:
                month = str(strptime(month,'%b').tm_mon)
        except:
            self.__log(u"XXX Date parse error: " + rawDate)
            return u"1770-01-01"
            pass

        if len(month) == 1:
            month = "0" + month
        if len(day) == 1:
            day = "0" + day
        return year + "-" + month + "-" + day
    elif re.match("[0-9][0-9][0-9][0-9]-[0-9][0-9]?-[0-9][0-9]?", rawDate):
        parts = rawDate.split("-")
        year = parts[0].strip()
        month = parts[1].strip()
        day = parts[2].strip()
        if len(month) == 1:
            month = "0" + month
        if len(day) == 1:
            day = "0" + day
        return year + "-" + month + "-" + day
    else:
        self.__log(u"XXX Date parse error: " + rawDate)
        return u"1770-01-01"

Am I on the right track or is there a better way to go?

Update By free form string I mean this is coming from a wiki page, specifically the person data template. The date fields in this template are free form in that a human has typed something in it. Typically this is a date in any number of formats, or it is itself another wiki template describing the date. Here are some examples of what could be in the field:

{{Birth year and age|1933}}
August 23, 1967
1990-01-29
23 August 1967
1999
a;lsdfhals;djkfh
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:22:29+00:00Added an answer on June 12, 2026 at 12:22 pm

    Probably the ultimate is parsedatetime.

    Another choice would be dateutil.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.