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?
The date() instance method of the python datetime class returns a date instance. Using this method only the date information excluding the time information is retrieved from a datetime instance.
Referring to the documentation, it doesn't appear that there is a character sequence for this. However, you could correct the result as follows:
today = currentDate.strftime('%m/%d/%Y').replace("/0", "/")
if today[0] == '0':
today = today[1:]
This will eliminate any leading 0
s so long as the values are split with a forward slash.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With