(SELF-FIXED) How to format date using python ?

January 3, 2015 at 09:55:27
Specs: Windows 7, 8 Gb

To get date I use this block:

currentDate = date.today()
today = currentDate.strftime('%m/%d/%Y')

It returns me this format 12/22/2014 or 01/02/2015 Then I have to compare to string from the file (note: I can't change the string) 12/22/2014 or 1/2/2015 and I use:

if l[0] == today:

In second case it obviously failed. My question: how could I change strftime() in order to return only one charachter for month and day when it has preceeding zero?
Please disregard my question, I was able to fix it by using this block:
today = currentDate.strftime('%m/%d/%Y').replace("/0", "/")
if today[0] == '0':
today = today[1:]

message edited by susja

See More: (SELF-FIXED) How to format date using python ?

Report •

January 3, 2015 at 22:56:43
I can't see how your solution worksnfor, e.g., "01/12/2014".

Report •

January 4, 2015 at 05:14:48
- ljack
when I set date as 01/12/2015 and ran that block it returned me 1/12/2015 hence it's working as I need it.

Report •

January 6, 2015 at 15:08:56
My bad! I was just looking at the first line, not the next two which strip the leading zero.

Report •

Related Solutions

Ask Question