Adding a duration to a start time string to get a finish time?

excel formula to calculate time worked
how to add time in excel
how to add hours to time in excel
how to calculate date and time difference in excel
excel calculate elapsed time between two dates
excel calculate hours between two times after midnight
how to add time in google sheets
how to add minutes and seconds in excel

I have a string called startTime and I want to add a duration (that's in minutes) to get a finishTime.

Here's some sample data:

startTime : 10:15

duration: 90

In python, what's the best way to add that duration so that the finishTime would be 11:45?

Thank so much, any help much appreciate.

Try this:

import datetime

d = datetime.datetime.strptime("10:12","%H:%m") + datetime.timedelta(minutes=90)
new = d.strftime('%H:%m')

new will be 11:45.

Fifth Annual Workshop on Space Operations Applications and , The two mandatory fields are the activity name and the duration of the activity. of the fields of the activity data structure: Name - string - this is used as the unique id. Temporal Constraints - timing constraints between the start or finish of one design of the activity data structure, it is trivial to add new fields to the activity. If you can tolerate the 3.3ms accuracy and rounding provided by the DATETIME data-type, the duration calculation is incredibly simple. Just subtract the start date and time from the end date and time.

I recommend using pandas for tasks like this, since it is much more intuitive to use than using the datetime module directly.

import pandas as pd
startTime = '10:15'
duration = '90'
finishTime = (pd.to_datetime(startTime , format='%H:%M') 
              + pd.to_timedelta(duration + 'min')).strftime(format='%H:%M')

As pointed out by Torxed and shmee, pandas is not a built-in module and it is fairly large with around 70MB, thus it may not be suitable for everyone. But since pandas is imho the best tool to process time series data and since the question looked like something which is commonly needed when processing time series, I thought a solution with pandas might be interesting/of use.

Calculating time in Google Sheets: subtract, sum and extract date , If you have your start time and end time, it's not a problem to find out the time spent: Time duration in hours and minutes in Google Sheets. To apply the custom time format, go to Format > Number > More Formats > Custom number You can use the TIME function to add or subtract up to 60 seconds:. Related Articles. Using the TIME data type in SQL Server 2008 (6 March 2008). Using the DATE data type in SQL Server 2008 (6 December 2007). DATEDIFF Function Demystified (20 March 2007)

You could use pd.to_datetime in order to convert the strings to datetime objects, and add the minutes using pd.to_timedelta. Finally convert the datetime to the desired format using strftime:

import pandas as pd
(pd.to_datetime( '10:15', format='%H:%M') + pd.to_timedelta(90, unit='m')).strftime('%H:%M')

Microsoft Excel 2010 Data Analysis and Business Modeling: Data , How can I use the TIMEVALUE function to convert a text string to a time? How do I extract the hour, minute, or second from a given time? before the start time, then 24*(finish time–start time) yields a negative number of hours, but adding 24​  Duration represents the amount of time a task is expected to take. Click on the Duration cell of a sub-task and type in the length of time. You can use a few different formats: Weeks (e.g. 2w) Whole working days (e.g. 4d) Partial working days (e.g. 3.5d) Hours (e.g. 7h). Minutes (e.g. 60m) Seconds (e.g. 500s) and milliseconds (e.g. 50000ms)

Calculate time in Excel: time difference, add, subtract and sum times, You will learn a few useful formulas to sum times and add hours, minutes or seconds to a given time. Another simple technique to calculate the duration between two To get the time difference in a single time unit (hours ,minutes or Supposing that your start time is in A2 and end time in B2, you can  We can first use the slow, looping method to add 1 to each value in our vector: g <- rnorm(100000) h <- rep(NA, 100000) # Start the clock! ptm <- proc.time() # Loop through the vector, adding one for (i in 1:100000){ h[i] <- g[i] + 1 } # Stop the clock proc.time() - ptm user system elapsed 0.34 0.06 0.41

Add or subtract time - Excel, Let's say that you need to add two different time values together to get a total. On the Home tab, in the Cells group, choose Format, and then choose Format Cells. In cell D2, subtract the end time from the start time by entering the formula  Hi Craig, thanks for your reply. i like the drop down idea, that will work well. the bit i am stuck on is how i can calculate total hours worked in a day from the start and finish times. eg start 8.15 and finish 4.30. how do i change time format into number format to get me total hours worked of 8 hours and 15 minutes???

AppleScript: The Comprehensive Guide to Scripting and Automation , Layout: Meeting DB Date 21.06.2006 Sta't'l'lme 933 AM I: ' End 'I'lme 1013] AM " A l You then tell this layout to delete any previous find requests; otherwise, these you write the starting time followed by three dots and then the finishing time. the text in those fields, you add two equals signs to the start ofyour strings. When times cross midnight. Calculating elapsed time is more tricky if the times cross a day boundary (midnight). For example, if the start time is 10:00 PM one day, and the end time is 5:00 AM the next day, the end time is actually less than the start time and the formula above will return a negative value, and Excel twill display a string of hash characters (#####).

  • Possible duplicate of Datetime strptime in python
  • Possible duplicate of What is the standard way to add N seconds to datetime.time in Python?
  • perfect thank you! I had a play and the %m should be %M but it fully works and I've since used that for some other conversions today as well. So know i know HOW it works also. Thanks again mister (and to everyone who helped)
  • Not at all debating that :) However, I feel that a recommendation to use a 3rd party lib should come along with some disclaimer stating that fact and should ideally contain a link to the package homepage/documentation if available. On an aside: I think you should add import pandas as pd for completeness sake :D
  • @shmee Me neither and thanks for the hint. :) I implemented both and added a short disclaimer.
  • @Torxed Thanks and not a problem at all. Also no upvote needed, if my solution is not what you'd support. I fully understand that pandas may not be the right tool for a simple case like this. Also thanks for pointing that out. I don't mind harsh words, but especially on the internet when you don't see the other person, a friendly comment may yield a better result.
  • Although I cannot speak for Torxed, I upvoted your answer because you have made it a complete and helpful one. It might not be the approach I'd take, but that does not make it less worthy of an upvote, imho.
  • I concur with @shmee. Just because I wouldn't use or don't like something, doesn't make it less viable/good. You have to set aside your own personal believes and look at things like these from a perspective of neutral and critical thinking. This is a good answer, no matter what I think or believe. It reflects some good points, It's helpful if you're willing to use external libraries - which you point out in your answer. That alone is worth an up-vote. Good manners should give extra credit, sadly there's no points for that - so you'll have to take my sentences for what they're worth. Good job:)
  • Why the downvote? reason please, perhaps I can improve the answer with your feedback
  • Perhaps you could give me some time to elaborate on my answer?
  • Again imho the comments from @Torxed are quite harsh. In my opinion, if someone tries to help, give him the appreciation. Even if the answer is not 100% perfect (especially in the first 15 seconds after posting it). But downvoting an answer right away is frustrating for someone posting an answer and trying to help... I thus upvoted your answer to compensate the downvote. ;)
  • Sure, I do the same thing. I post a semi-complete answer every day. But I make sure the code provided can be executed as-is before posting. Otherwise, you're posting for the points and glory not to be helpful. I'll get hate for not being polite here, but the truth is that this answer isn't helpful - as is at the moment. You can't run this, there's no explanation as to where these functions are imported from. The answer was two words "use this:" and then code that can't be executed. What's more harsh, giving someone something they can't use or pointing out "this isn't useful"?
  • Totally agree and appreciate your comment, returned :)