[Tutor] Working with dates

Liam Clarke cyresse at gmail.com
Sun Oct 17 11:06:24 CEST 2004


Thanks all for your responses, 

I think one of my weaknesses in this is a poor understanding of how to
properly utilise classes.

gm_data=time.gmtime()...

....((split_date[2]), 0, 0, 0, 0, 0, 0))

I have 2 datetime.date instances there, and I'm not using them to
their full capability, looking at Kent's example

'lastFriday=datetime.date.today()' I gather this creates a date
instance called lastFriday and gives it today's date/time values?

'while lastFriday.weekday() != 4:'  and I'm guessing that the method
weekday in class date generates an integer value for day of the week,
and that it generates that based on the stored date in lastFriday.

'lastFriday -= oneday' I don't quite understand what  -= does. 
It's not a boolean/arithmetic operator? Is it peculiar to the datetime
module? I'm guessing it increments the date stored in lastFriday back
by period oneday?

what is different between - and -= ?

'print lastFriday.strftime('%d-%b-%Y')' and of course, you can
generate a string direct from lastFriday using the strftime method...
( because datetime supercedes the date and time modules?)

It's all very clear to me now, hindsight is great that way.

(Just spent ten minutes rereading manual on date class, and it now
makes more sense, this OOP thing.)

I read the tutorials on OOP, but it kind of went over my head.

So an instance of the class date, can hold variables such as year etc.
and then run a contained function (like strftime) on that variable....

the light dawns....

Danny, I don't quite understand what datetime.date.resolution does
exactly. Your function generates the targetTime, and checks that it
hasn't already happened, but if it does it adds DAYDELTA?

Thank you for your knowledge and help. I'm learning heaps. 
And Kent, your code does exactly what I need, and so elegantly too.


More information about the Tutor mailing list