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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:25:03+00:00 2026-06-10T19:25:03+00:00

I need to break down a date in python into: year, month, day and

  • 0

I need to break down a date in python into: year, month, day and time(hour).

I have a list of objects, each object has a date property:

startDate=db.DateTimeProperty(auto_now_add=True)

The date property containts, the year, the month, the day and the time all in one.

I wish to create a new nested list(dictionary) where:

Outer list- is a list of years(that are present in at least one of the input dates) -> inside each year a list of months(that are present during that year in at least one of the input dates)-> inside this days(same as with months – days present in the input list) -> Inside that a list of times(hours)… each our pointing to it’s respective object.

I hope this is easily understood.

If I get the list bellow as input:

{obj1 -> (2000 Dec 18 9:00AM), obj2 -> (2000 Dec 19 1:00PM)}

It will clamp them together so I’ll have

(2000) -> (Dec) -> {(18) -> (9:00AM) -> obj1 ,(19) -> (1:00PM) -> obj2}

I hope this makes sense..

Basically I have a lot of events with dates and I want to list them like this:

Year ->
Month(s) of interest->
Day(s) of interest->
(event times)
.
.
.

Another Year ->
Relevant Month(s) ->
Relevant Day(s) ->
(event times)
.
.
.

Instead of:

(Event1 : complete date & time) , (Event2 : complete date & time) , (event3 : complete date & time)

Thanks

  • 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-10T19:25:05+00:00Added an answer on June 10, 2026 at 7:25 pm
    class a: ## Using this class just to explain
        def __init__(self,y,m,d,t):
            self.y=y
            self.m=m
            self.d=d
            self.t=t
    
    
    o1 = a(2000,12,18,9) ## Just assuming integers here. you can choose immutable objects here
    o2 = a(2000,12,19,13)
    o3 = a(2001,11,18,9)
    o4 = a(2000,11,18,6)
    o5 = a(2000,12,6,7)
    
    l=[o1,o2,o3,o4,o5]
    
    
    d={}
    
    for o in l:
        if o.y not in d:
            d[o.y] = {}
        # print d
        if o.m not in d[o.y]:
            d[o.y][o.m]={}
        if o.d not in d[o.y][o.m]:
            d[o.y][o.m][o.d]={}
        if o.t not in d[o.y][o.m][o.d]:
            d[o.y][o.m][o.d][o.t]=o
    

    You can try producing a better formatted output:

    for k,v in d.items():
        for j,h in v.items():
            print k,j,h
    

    I get output as:

    2000 11 {18: {6: <__main__.a instance at 0x0232E9E0>}}
    2000 12 {18: {9: <__main__.a instance at 0x0232E940>}, 19: {13: <__main__.a instance at 0x0232E990>}, 6: {7: <__main__.a instance at 0x0232EA08>}}
    2001 11 {18: {9: <__main__.a instance at 0x0232E9B8>}}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to break down a JSON string into smaller objects. I have two
I need to break down a binary number into 4 decimal digits using assembly.
I have a need to take a time period, e.g. a week and break
Suppose you are calling a function, where there's clearly a need to break down
I need to force page break after each record from datasource. I tried <break
I need to break down the amounts on their respective bill/coin. The output is
I have a vector of temperatures and a cell array of Date/Time. I want
I just started work on a C# application. I need to break down a
needing some help to just break down the problem. I have new users who
I need to break apart a string that always looks like this: something --

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.