Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8716639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:07:58+00:00 2026-06-13T06:07:58+00:00

I’m converting a PHP program to Python. Apparently MySQLdb returns MySQL time fields as

  • 0

I’m converting a PHP program to Python. Apparently MySQLdb returns MySQL time fields as time deltas offset from midnight. So a database field containing a literal “08:00:00” (8:00 AM) is returned as 28,800 seconds. I have found some other posts confirming this behavior, but can’t find code samples that help me get what I need.

I need to read a logged event’s date and time, and determine how much time has passed:

event_date = mysql_result[0] # datetime object
event_time = mysql_result[1] # timedelta object

now = datetime.now()         # datetime object
elapsed_minutes = ???        # need integer

Iv’e read through the lengthy documentation for datetime on docs.python.org, but have been unsuccessful taking the datetime and timedelta values, comparing to the current time, and producing the number of elapsed minutes (or seconds) as an integer.

I’m not saying the answer isn’t there or in another stack overflow post–just that I have been completely unsuccessful finding and implementing it myself. Can someone please lend a hand?

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T06:07:59+00:00Added an answer on June 13, 2026 at 6:07 am
    In [82]: import datetime as dt
    In [85]: now = dt.datetime.now()
    
    In [129]: event_date = dt.date(2012,10,22)    
    In [155]: event_date = dt.datetime(event_date.year, event_date.month, event_date.day)
    
    In [130]: event_time = dt.timedelta(seconds = 28800)    
    In [131]: event = event_date + event_time  
    
    In [132]: elapsed = now - event
    Out[132]: datetime.timedelta(0, 35008, 781476)    
    In [133]: elapsed.total_seconds()
    Out[133]: 35008.781476    
    In [134]: elapsed.total_seconds() // 60
    Out[134]: 583.0
    

    Or, in Python2.6, which does not have the total_seconds method:

    In [149]: (elapsed.days*24*60*60+elapsed.seconds+elapsed.microseconds/1e6)//60
    Out[149]: 583.0
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I would like to count the length of a string with PHP. The string
I've tracked down a weird MySQL problem to the two different ways I was
I have a text area in my form which accepts all possible characters from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.