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 8801697
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:54:03+00:00 2026-06-14T00:54:03+00:00

In Sweden we sometimes use a strange date format, for example New Year is

  • 0

In Sweden we sometimes use a strange date format, for example New Year is the 31/12. If I have this format as a string ,which can be any date between 1/1 and 31/12, and if we assume that it is this year, how do I get into a standard date format using Python (format as 2012-01-01 and 2012-12-31) that can be sore in be stored as a date in a mySQL database.

  • 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-14T00:54:05+00:00Added an answer on June 14, 2026 at 12:54 am

    Simply split the two values, map them to integers and update a datetime.date() instance:

    import datetime
    day, month = map(int, yourvalue.split('/'))
    adate = datetime.date.today().replace(month=month, day=day)
    

    By using datetime.date.today() we get the current year.

    Demo:

    >>> import datetime
    >>> somevalue = '31/12'
    >>> day, month = map(int, somevalue.split('/'))
    >>> datetime.date.today().replace(month=month, day=day)
    datetime.date(2012, 12, 31)
    >>> someothervalue = '1/1'
    >>> day, month = map(int, someothervalue.split('/'))
    >>> datetime.date.today().replace(month=month, day=day)
    datetime.date(2012, 1, 1)
    

    Alternatively, you could use the datetime.strptime() method to parse these dates, but you’ll have to manually correct the year afterwards (it’ll use 1900 as the default if no year is being parsed):

    adate = datetime.datetime.strptime(yourvalue, '%d/%m').date()
    adate = adate.replace(year=datetime.date.today().year)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this Excel table: country year 1 2 3 4 Netherlands 1970 3603
I have 500 CSV files in this format: IndicatorA_Name.csv 1900 1901 1902 ... Norway
Ive got this problem where I need to check an arrayposition if the string
Been kind of stuck on this one for a while now, so any help
I have a problem that I can't figure out myself. I've tried using LEFT
I'm using the Basic database plan at Heroku. This runs on Postgres 9.1 which
Just wondering if anyone has experience with this. I have a plain text in
I'm trying to convert the string 18 December 2009 (Sweden) to 2009-12-18 but I
I have a 35 MB Excel file with these columns: Index, Name, Year, AgeGroup1,
I have a table of users, and in this table I have a country

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.