[Tutor] datetime: inverse of datetime.date.isocalendar()

Albert-Jan Roskam fomcl at yahoo.com
Fri Jul 12 21:58:16 CEST 2013



_______________________________
> From: Alan Gauld <alan.gauld at btinternet.com>
>To: tutor at python.org 
>Sent: Friday, July 12, 2013 9:00 PM
>Subject: Re: [Tutor] datetime: inverse of datetime.date.isocalendar()
> 
>
>On 12/07/13 17:52, elmar werling wrote:
>
>> how to convert the tuble (iso_year, iso_week, iso_day) to a date object?
>>
>> I have tried the following scipt, but the results are buggy
>
>Thanks for sending the code but can you define buggy?
>What did you expect? What did you get?
>Were there any error messages if so what (full text please)?
>
>
>> import datetime
>>
>> date_i = datetime.date(2013, 07, 12)
>> date_iso = date_i.isocalendar()
>>
>> year = str(date_iso[0])[2:]
>> week = str(date_iso[1])
>> day = str(date_iso[2])
>>
>> date_string = year + week + day
>
>But guess is there is a better way of doing the lines above
>but I don't know the datetime module well enough to say what...

Maybe this:

>>> import datetime>>> "%d%02d%02d" % datetime.date(2013, 07, 12).isocalendar()
'20132805'


More information about the Tutor mailing list