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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:38:49+00:00 2026-06-16T00:38:49+00:00

I have a string 2012.11.07 in python. I need to convert it to date

  • 0

I have a string "2012.11.07" in python. I need to convert it to date object and then get an integer value of day of year and also Julian day. Is it possible?

  • 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-16T00:38:50+00:00Added an answer on June 16, 2026 at 12:38 am

    First, you can convert it to a datetime.datetime object like this:

    >>> import datetime
    >>> fmt = '%Y.%m.%d'
    >>> s = '2012.11.07'
    >>> dt = datetime.datetime.strptime(s, fmt)
    >>> dt
    datetime.datetime(2012, 11, 7, 0, 0)
    

    Then you can use the methods on datetime to get what you want… except that datetime doesn’t have the function you want directly, so you need to convert to a time tuple

    >>> tt = dt.timetuple()
    >>> tt.tm_yday
    312
    

    The term “Julian day” has a few different meanings. If you’re looking for 2012312, you have to do that indirectly, e.g., one of the following.

    >>> int('%d%03d' % (tt.tm_year, tt.tm_yday))
    2012312
    >>> tt.tm_year * 1000 + tt.tm_yday
    2012312
    

    If you’re looking for a different meaning, you should be able to figure it out from here. For example, if you want the “days since 1 Jan 4713 BC” meaning, and you have a formula that requires Gregorian year and day in year, you’ve got those two values above to plug in. (If you have a formula that takes Gregorian year, month, and day, you don’t even need the timetuple step.) If you can’t work out where to go from there, ask for further details.

    If you don’t have a formula—and maybe even if you already do—your best bet is probably to look around PyPI and ActiveState for pre-existing modules. For example, a quick search turned up something called jdcal. I’d never seen it before, but a quick pip install jdcal and a brief skim of the readme, and I was able to do this:

    >>> sum(jdcal.gcal2jd(dt.year, dt.month, dt.day))
    2456238.5
    

    That’s the same result that the USN Julian date converter gave me.

    If you want integral Julian day, instead of fractional Julian date, you have to decide which direction you want to round—toward 0, toward negative infinity, rounding noon up to the next day, rounding noon toward even days, etc. (Note that Julian date is defined as starting since noon on 1 Jan 4713BC, so half of 7 Nov 2012 is 2456238, the other half is 2456239, and only you know which one of those you want…) For example, to round toward 0:

    >>> int(sum(jdcal.gcal2jd(dt.year, dt.month, dt.day)))
    2456238
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to convert a timezone-aware string like 2012-11-01T04:16:13-04:00 to a Python datetime object.
I have string value with date(for ex.: 2012-11-30T12:45:00Z ), how can I get value
I have this string: '2012-02-10' # (year-month-day) and I need it to be as
I have the following string: 2012-12-10T23:40:41Z My goal is to get the day as
I have this string 2012-06-27 16:17:06 and I want to convert it to GMT
I have the following string assigned to a variable: $date = 16 June, 2012,
I have this string: tag:domain.com,2012-10-12:feed/channel/id/335 Im trying to get the last digits from this
I have a date string with the following format: 2012-09-20T01:36:51.556Z Its a date field
I have a string as follows: 2012-11-01 And I want to get a string
I have a date string like 2012/10/11 21:46:31 +0000 And I have tried almost

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.