Marco Dinatsoli
Marco Dinatsoli

Reputation: 10570

python strftime not working with hours minutes and seconds

I am reading the official documentations here

https://docs.python.org/2/library/datetime.html#strftime-strptime-behavior

and it states that I can use

%H and %M and %S for hours, minutes and seconds

I do this:

datetime.date.today().strftime("%Y-%m-%d %H:%M:%S")

and I always get

'2016-07-18 00:00:00'

where are the values ?

Upvotes: 20

Views: 47409

Answers (1)

juanpa.arrivillaga
juanpa.arrivillaga

Reputation: 95908

You are asking for a date, which doesn't include a time. You want a datetime:

datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

Example:

In [3]: datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
Out[3]: '2016-07-18 18:26:18'

Upvotes: 51

Related Questions