date

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Mar 2 07:45:10 EST 2015


greymausg wrote:

> I have a csv file, the first item on a line is the date in the format
> 2015-03-02 I try to get that as a date by date(row[0]), but it barfs,
> replying "Expecting an integer". (I am really trying to get the offset
> in weeks from that date to today())

What is "date"? Where does it come from?

If it is your own function, then we cannot help you unless you show us the
code for it.

If you mean the standard library date, then you should say so.


py> from datetime import datetime
py> today = datetime.today()
py> astring = "2014-12-27"
py> another_day = datetime.strptime(astring, "%Y-%m-%d")
py> difference = today - another_day
py> difference.days
65
py> difference.days/7  # weeks
9.285714285714286


-- 
Steven




More information about the Python-list mailing list