[EMAIL PROTECTED] wrote:
> Hello there
>
> Messing around with certain time and datetime objects, I have managed to 
> subtract a date/time from the present time thusly:
>   

datetime is definitely a module that takes a little getting used to.

> from time import *
>   

(Bad form)

> import datetime
>
> one = datetime.datetime.now()
> two  = datetime.datetime(2007, 8, 29, 11, 15, 00)
>
> difference = one - two
>
> print difference
>
> However, I have to take a date from a file and then insert it to where two 
> should be, however to no success. I have managed to get a string containing 
> the above date/time, but that is as far as I've gotten without it not 
> working.
>   

You don't show the format of the date string, but I'll show an example:

 >>> from datetime import datetime
 >>> start = datetime.strptime( '10:24:03 2006-11-01', '%H:%M:%S %Y-%m-%d' )
 >>> end = datetime.strptime( '11:10:33 2006-11-01', '%H:%M:%S %Y-%m-%d' )
 >>> delta = end - start
 >>> print delta.seconds
2790

Is that what you need?

Take a skim through the library reference for the entire module.  The 
result of the subtraction is a timedelta object, you kind of need to 
know what's available overall to be able to pick out the right 
functionality.

Hope that helps,
e.

> Does anyone have any ideas on how to do this properly?  
>
> Also I wish to display the result only in seconds left, rather than the 
> current result, which just displays days/hours/minutes/seconds/milliseconds 
> left, but am again struggling to progress.
>
> Any help would be amazingly appreciated :)
>
> Thanks again
>
> -Dave
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>   

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

Reply via email to