calculate dates in python
<pre><code>def main(filename, from_str, to_str):
    date_from =time.strptime(from_str, "%Y-%m-%d %H:%M")
    date_to = time.strptime(to_str, "%Y-%m-%d %H:%M")
    print date_from, date_to
    days = (date_from - date_to).days
    print days

if __name__ == "__main__":
    if len(sys.argv) &lt; 1:
        print "Usage: %s DATE [e.g. 2011-09-08 2011-10-08]"
        sys.exit(1)
    main("servanet-" + sys.argv[1] + sys.argv[2]+ ".txt", sys.argv[1] + " 00:00", sys.argv[2] + " 23:59")
</code></pre>

<p>This is part of my code, I want to calculate the days from the input, (I don't need to calculate minutes and seconds,just days in this case, but I will use the minute and the second information later in the code, so I need to keep them like this) ,but it seems, (date_from - date_to).days cannot work with minutes and seconds after it, how can I solve this problem?</p>

<p>Many thanks!</p>

<p>========comments: I think I cannot simply use day2-day1. since if they are from different month, the result will be wrong, like from 2011-08-01 to 2011-09-02</p>
