This script of mine, < http://py77.python.pastebin.com/f2fdcb99c>, has a function that prints the result--the difference in days, and weeks and days, between two dates.

The function is

def printResult(date1, date2, days1, weeks, days2):
    print "\nThe difference between %s and %s is %d days" % (date1.strftime("%m/%d/%Y"),
        date2.strftime("%m/%d/%Y"), days1)
    print 37 * " ",
    print "Or %d weeks and %d days" % (weeks, days2)
    print ((len(str(weeks)) + len(str(days2))) + 57) * "="

An example output is:

The difference between 05/06/2008 and 11/04/2008 is 182 days
                                      Or 26 weeks and 0 days
============================================================

Nicely right-justified, but that's not always the case:

The difference between 07/04/1776 and 09/11/2001 is 82248 days
                                      Or 11749 weeks and 5 days
===============================================================

Isn't there an easier way, something built into Python, that would do the job?

Thanks,

Dick Moores
_______________________________________________
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor

Reply via email to