How to Add & Subtract time code in Python

I have been developing some tools for the media production lately, i found a neat way to add or subtract certain amount of seconds to a given time code.

for example i have a video that starts from 12:45:05 and i want to add 59 seconds to it and use the new time.

from datetime import datetime
from datetime import timedelta
 
time = datetime(2009, 1, 1, 12, 45, 05, 0)
 
diff = timedelta(seconds = 59)
 
final_time = time + diff
  • Share/Bookmark

No related posts.

Tags: , , ,

2 comments

  1. Nice example!
    If you have more such useful tips please post them at http://www.php2python.com too. I’m trying to build a resource for people moving from php to python.

  2. Thanks for the reply
    actually i am not moving from php to python, each tool has its powerful area of use.
    I like php for web & python for Desktop, i visited your website, good one :)

Leave a comment