This is my code:
import datetime
today = datetime.date.today()
print today
This prints: 2008-11-22 which is exactly what I want BUT....I have a list I'm appending this to and then suddenly everything goes "wonky". Here is the code:
import datetime
mylist = []
today = datetime.date.today()
mylist.append(today)
print mylist
This prints the following:
[datetime.date(2008, 11, 22)]
How on earth can I get just a simple date like "2008-11-22"?
With type-specific
datetime
string formatting (see nk9's answer usingstr.format()
.) in a Formatted string literal (since Python 3.6, 2016-12-23):The date/time format directives are not documented as part of the Format String Syntax but rather in
date
,datetime
, andtime
'sstrftime()
documentation. The are based on the 1989 C Standard, but include some ISO 8601 directives since Python 3.6.I don't fully understand but, can use
pandas
for getting times in right format:And:
But it's storing strings but easy to convert:
You may want to append it as a string?