<div class="gmail_quote">On Thu, May 6, 2010 at 2:42 PM, Chris Rebert <span dir="ltr"><<a href="mailto:clp2@rebertia.com">clp2@rebertia.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
On Thu, May 6, 2010 at 1:47 AM, Kurian Thayil <<a href="mailto:kurianmthayil@gmail.com">kurianmthayil@gmail.com</a>> wrote:<br>
<snip><br>
<div class="im">> the expected output is 05:35:05.<br>
><br>
> Now, here is code snippet,<br>
><br>
> cursor1=getconnect1.cursor()<br>
> getrows=cursor1.execute("""SELECT<br>
> TIME(DATE_ADD(info_last_calltime, INTERVAL %s MINUTE)) FROM rem_call_info<br>
> WHERE info_ctrlid=%s""", (retryinterval,controlid1,))<br>
> rawstatus20result=cursor1.fetchone()<br>
> print "Raw result is",rawstatus20result<br>
> status20result=rawstatus20result[0]<br>
> print "The query result for Status<br>
> 20:",status20result,";Time now is",timeformat<br>
><br>
> The output is:<br>
><br>
> Raw result is (datetime.timedelta(0, 20105),)<br>
> The query result for Status 20: 5:35:05 ;Time now is 05:22:00<br>
> Match not found.<br>
> New call to be made<br>
> Getting next value if any...<br>
><br>
> If you look closer, the time fetched by python module was 5:35:05 instead of<br>
> 05:35:05. How can I get this time format? Thanks in advance.<br>
<br>
</div>You're getting back a time delta (i.e. quantity/duration of time, e.g.<br>
"3 hours") rather than an actual time (i.e. temporal coordinates for a<br>
particular instant of time, e.g. "5:15PM and 2 seconds"), and<br>
timedelta defines its stringification differently, hence your issue. I<br>
would guess that getting back a timedelta instead of a time is some<br>
quirk of MySQLdb; haven't used it though, so I'm just guessing.<br>
<br>
Anyway, you can work around this by converting the timedelta object to<br>
a time object yourself:<br>
#Untested Code!<br>
from datetime import time<br>
minutes, seconds = divmod(status20result.seconds, 60)<br>
hours, minutes = divmod(minutes, 60)<br>
time_result = time(hours, minutes, seconds, status20result.microseconds)<br>
print "The query result for Status 20:",time_result,";Time now is",timeformat<br>
<br>
Cheers,<br>
Chris<br>
<font color="#888888">--<br>
<a href="http://blog.rebertia.com" target="_blank">http://blog.rebertia.com</a><br>
</font></blockquote></div><br>That worked Chris. Thank you.<br><br>Regards,<br><br>Kurian Thayil.<br><div style="visibility: hidden; display: inline;" id="avg_ls_inline_popup"></div><style type="text/css">#avg_ls_inline_popup { position:absolute; z-index:9999; padding: 0px 0px; margin-left: 0px; margin-top: 0px; width: 240px; overflow: hidden; word-wrap: break-word; color: black; font-size: 10px; text-align: left; line-height: 13px;}</style>