Subtracting times across a day in excel - excel

I am working on the capstone project in of the Google Career Certificate in Data Analytics. I am using Microsoft Excel. I have to calculate the ride length based on the start and end ride times. I've inputted the formula =F2(end time)-D2(start time) which returns the ride length. Going through my entire list I have some areas where the start time is like 11pm and the end time is 1am and this is returning ###### because it is a negative number with the regular formula. I've found a modified formula that can kind of do the conversion I am looking for but it is still a bit problematic. The modified formula is =(F2-D2+(F2<D2))*24 and it seems to give an accurate ride length if I reformat the answer to number. The issue is the rest of my data is in time format and the modified ones are in number format. If I convert the number values to time, the ride length values are inaccurate.
It is tricky to make the numeric value change as well due to me using a formula. I can correct them one by one after I save Excel and it no longer stores the numbers as the formula, but there are lots of data points to change and that would be time consuming. I'm hoping to find a more concise way to solve this problem. Maybe with a better formula.
[Snippet of the chart 1

Just like everything in life, there are multiple ways to achieve things. I would have formatted the date and time into a single cell; but. if you're gathering the data from another source, that's understandable.
A simple IF statement here will work. IF the days are one apart, then take '1' day off the starting time, else do your original formula:
=IF(E4-C4=1,F4-(D4-1),F4-D4)

Related

Reducing duration by a percentage in excel

I have been racking my brain for hours on how to do this, so I am reaching out to some of you excel experts.
Say you have a duration represented as 1d 14:25:00 and you want to reduce that by a given percent, such as 149.5%, how can this be done?
At first I thought about going down the route of having a cell formatted in time, but when you try and do math against it, it fails.
Then I thought about maybe converting the time down to seconds and working with that, but that seems like it is total pain in the rear. It involves a lot of converting from time to number then back to time to display it. There has to be an easier way.
It depends on how you format the cell to read the Date/Time. If it's represented as a Time, then I believe the best approach is to convert the percentage into a decimal number (i.e 150% = 1.5), then use that in your formula.
However, it also requires applying the cell format to the custom format of [h]:mm:ss to include any times above 24 hours. See the image below for an example.
Time Conversion Example:
The only alternative is a "pain in the rear" - breaking the time down into seconds.
Excel includes built-in functions to convert a Date/Time into HOUR(date), MINUTE(date), and SECOND(date). Unfortunately, getting the number of days requires calculating the difference between two times: DAYS(end_date, start_date). I used this in the example above for the rows titled Conversion.

Excel function for First Row and Last Row of group

I have a gate keeping report with a number of entry/exit times for an employee over a 24hr period.
I need another formula to go into I40 which is the difference between the first entry time - last entry time for each employee eg. I40 = F50 - D40.
Dont worry about the formula regarding the subtraction of dates as I have this. I really just need the formula that will allow me to get the Last Exit time cell and the First Entry time cell for each employee.
The best way is to always store datetime values (ie, 2018-05-24 13:454) instead of just the times. You could still display it as a time by changing the cell's formatting to a time format.
Shortcut to Number Formatting options: Ctrl+1
There are many advantages, including that "regular math" will still work even if a shift starts in a different day than it ends.
If you must stick with only times, you can still calculate it correctly (up to a 23.9-hour shift) with an IF statement to add a day if the returned value is negative.
For example, if your existing formula works for same-day shift, and is:
=F50-D40
...then you could change it to:
=IF(F50-D40<0,F50+1-D40,F50-D40)
More Information:
Office.com : How to use dates and times in Excel
Office.com : Add or subtract time (Excel)
EDIT:
Looking at your question again, perhaps I misunderstood what you were trying to ndo. It's a little unclear, but you mention the fist and last times.
If you mean the "earliest and latest", you can get those using MIN and MAX. If the crossing-midnight is an issue here too, you'll need to see my first suggestion above, or else add a "helper column" to determine which times are before which.
Storing datetime is still best and this all would have been avoided.
try the below to get the difference in hours.
=(E50+F50)-(C40+D40)

Joining a date and time into a single cell in Excel / VBA

I have to report basically the same information from inspections to two different clients, both of whom have provided me with an Excel spreadsheet in their own preferred format, and password protected. I have put the two sheets into my own workbook, and have managed to get 'almost' all the data on both sheets to populate from my own data. Where I am stuck though is on the time logs.
Client 'A' has each time and date in a single column, in the format "12.29.12 14:30". Client 'B' has two columns, date as "12/29/12" in the first, and time as "1430" in the second.
I'm trying to avoid having to type all the same dates and times twice - it can be several dozen lines - both to save effort and to avoid errors. What I really need to do is either concatenate the date and time from client 'B's report and put it into client 'A's, or split the date and time up in 'A's so I can put it ito 'B's. I've tried several approaches, but just end up with error codes or meaningless numbers.
Can anyone point me in the right direction?
Thanks,
Richard
Never mind... the very next thing I tried worked :-)
To anyone else reading this, the trick is not to concatentate the date and time values, but to add them together.
Richard
As you later pointed out in your own question, in order to manipulate date/times in Excel, you should add instead of concatenating.
The reason for this is that Excel stores all date/times as a number representing the number of days since January 1, 1900*. This number is stored as a 8-byte double.
Use Excel number formats to display the date/time format that you desire.
If you find in a worksheet that some cell's dates are in fact stored as text, use the DATEVALUE function.
*By default, Excel 2010 for Windows uses the number of days since 1900. There is an option to use the number of days since 1904 for compatibility with other versions.

Converting TEXT that represents NEGATIVE TIME value to a number or time value for adding (Excel)

I've got a spreadsheet (Office 2007 version of Excel) full of text entries that are negative time values, example "-0:07" as in an employee took 7 mins less to complete a job than expected. I need to perform mathematical calculations on these entries and am looking for a more elegant formula/method than I've come up with so far.
I know about 1904 date system and * or / by 24 to convert back and forth, the problem is getting a formula that will recognize the text entry as a negative time value.
I've tried value(), *1, which both work on the text fields if the number is positive, but the "-" seems to mess those up. Even paste-special/add fails to recognize these as numbers.
Here's what I came up with that gets the job done, but it's just so ugly to me:
=IF(LEFT(E5,1)="-",((VALUE(RIGHT(E5,LEN(E5)-1)))*-1.0),VALUE(E5))
Obviously my text entry is in cell E5 in this example.
This works, so I'm not desperate for a solution, but for educational purposes (and smaller code) I'd like to know if there's a better way to this. Does anyone have a suggestion for something shorter, easier?
Thanks.
P.S. - an interesting tidbit here, I use Excel at work, but not at home, so I uploaded a sample spreadsheet to Google Docs, and it actually handles the Value() command on those entries properly. Weird, huh?
Thanks again for any suggestions.
Excel doesn't handle time spans in cells. It only deals with time. When you do "00:07" it is then converted to 0.0048611 which is the same as Jan 1st 1900 12.07 am. So if you did 2 minutes minus 7 minutes it would give at best 11.55pm.
The way you do it is the only way.

MS-Excel Negative times

I'm writing a spreadsheet for a shop manager. What it does is keep track of the number of hours a worker has worked.
So you enter times for Monday-Sunday, and then an adjustment - e.g. if they work 40/40/40/32 hours for the month, then you would have an adjustment of -2/-2/-2/+6 to bring the worker to the 38 hour week that he's being paid for. Some (most) weeks may be adjusted for overtime. The spreadsheet then totals the hours.
This spreadsheet is supposed to just be a self-calculating version of a paper form.
It needs to match the paper form as it has to be substituted for the old form which is given to some other member of the company (pay clerk, I don't know; I'm not rebuilding their whole system, just replacing a form)
I'm having trouble entering a negative time in the adj field - the field has a [h]:mm formatting. and when i enter a negative time (e.g. -2:00) it displays an error, saying "incorrectly formatted equation", with the suggestion that if I was entering a string then I should prefix with a apostrophe.
How do I overcome this?
Tools - Options - Calculation - 1904 date system
Check this box to use the 1904 (Mac) date system and you will be able to use negative dates and times. I'm not sure how this will effect existing spreadsheets, so maybe someone else can speak to that.
According to Excel...
"Dates and Times that are negative appear as ########"
Doesn't sound like you're going to be able to do that with an auto-summation formula. You'll have to set the formatting as none and just type it in (which defeats the purpose).
I am solving the same problem. Setting for date formatting "1904" is necessary for both below described solution.
You can enter an equation as a result of predeceasing cells like C5-C4-C3 (check out-check in-standard working time). The result is negative and it will be displayed like -1:15 and you can further process it.
Second way was already described above - to put into the requested cell a negative decimal value as a fraction of "1". "1,000"=24 hours, "0,5"=12 hours, "0,01"= 14 minutes, "0,041667"=1 hour. You have to find the correct decimal numbers first.

Resources