0

I have written code to generate all the dates for the given month:

nb_days = monthrange(2016, 2)[1]
dateDict = [datetime.date(year, month, day) for day in range(1, nb_days+1)]
outputItems = []
for dd in dateDict:
    outputItems.append(dd.strftime('%Y-%m-%d'))

My output is something like this:

['2016-02-01', '2016-02-02', '2016-02-03', '2016-02-04', '2016-02-05', '2016-02-06', '2016-02-07', '2016-02-08', '2016-02-09', '2016-02-10', '2016-02-11', '2016-02-12', '2016-02-13', '2016-02-14', '2016-02-15', '2016-02-16', '2016-02-17', '2016-02-18', '2016-02-19', '2016-02-20', '2016-02-21', '2016-02-22', '2016-02-23', '2016-02-24', '2016-02-25', '2016-02-26', '2016-02-27', '2016-02-28', '2016-02-29']

I need get result something like:

[('2016-02-01', '0', '0', '0'), ('2016-02-02', '0', '0', '0'), ('2016-02-03', '0', '0', '0'), ('2016-02-04', '0', '0', '0'), .....]
2
  • You could try something like this, outputItems.append(((dd.strftime('%Y-%m-%d'),)),) I don't understand what are '0's in ('2016-02-01', '0', '0', '0') Its upto you how you add them. Commented Nov 28, 2016 at 5:34
  • '0' it is just a value. Thank you it helped me! Commented Nov 28, 2016 at 5:39

1 Answer 1

1

Try this outputItems.append( (dd.strftime('%Y-%m-%d'), '0', '0', '0') )

nb_days = monthrange(2016, 2)[1]
dateDict = [datetime.date(year, month, day) for day in range(1, nb_days+1)]
outputItems = []
for dd in dateDict:
    outputItems.append( (dd.strftime('%Y-%m-%d'), '0', '0', '0') )
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.