[[+content_image]]
N
N
novicheck2016-08-03 15:09:03
Python
novicheck, 2016-08-03 15:09:03

How to find the minimum (earliest) date?

There is a list with lists of dates:

[, [[datetime.datetime(2016, 7, 31, 19, 29, 56, 608000), datetime.datetime(2016, 7, 31, 19, 29, 56, 605000)]]]

It is necessary for each list with dates to find the earliest.
Tried to do like this:
for date in dates:
  check = datetime.timestamp(date)
  if check mindate:
    mindate = check
  dateofstartpay1.append(mindate)
print(dateofstartpay1)
but this is what happened:
AttributeError: type object 'datetime.datetime' has no attribute 'timestamp'
. For the life of me, I can’t understand what the problem is and how to redo it so that everything works as it should.

Answer the question

In order to leave comments, you need to log in

[[+comments_count]] answer(s)
A
abcd0x00, 2016-08-04
@novicheck

>>> import datetime
>>> 
>>> lst = [[datetime.datetime(2016, 6, 19, 23, 5, 33, 899000),
...         datetime.datetime(2016, 6, 19, 23, 5, 33, 897000)],
...        [datetime.datetime(2016, 7, 31, 19, 29, 56, 608000),
...         datetime.datetime(2016, 7, 31, 19, 29, 56, 605000)]]
>>> 
>>> list(map(min, lst))
[datetime.datetime(2016, 6, 19, 23, 5, 33, 897000), datetime.datetime(2016, 7, 31, 19, 29, 56, 605000)]
>>>

If your list is incorrectly made (many superfluous nested lists), then first you need to bring it to the correct form; no need to write code for the wrong list.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question