Date Arithmetic Microsoft excel - excel

I'm trying to subtract Column B from Column A in excel to find out how many hours have passed between these two times but so far no luck.
Column A | Column B
05/01/11 11:54 | 05/01/11 08:46
I appreciate your help
Tried all the TIME related functions and did lots of research online but nothing.

The following formula should do what you want:
INT(A2-B2)&" days "&TEXT(A2-B2,"h"" hrs ""m"" mins """)

You can use the hour function
Hour(B1-A1)
which gives 3
Here is a link to another solution: https://stackoverflow.com/a/2324935/4293532
Note: Make sure that your data are formatted as dates, they are generally aligned to the right.

If you want it in hours rather than days and hours
=(A1-B1)*24
(which can be rounded down if you want whole hours)

Related

Excel Formula for calculating time in round numbers with hours text

I'm trying to figure out a way to create an excel spreadsheet that will allow me to keep track of how many hours I've earned per each paid holiday my company offers, then keep track of how many hours I've used and what's remaining. But I'm unsure how to calculate this properly.
I could easily do the math my self as it's a simple lay out, but I'm trying to find a way that will just let me enter the numbers for earned and used and walk away from anything else.
What I'm trying to do is the follow:
Have multiple sections. In the first section it'll be my holidays. So in like Column A, working down I'd have New Years, Memorial Day, July 4th, etc. Column B working down would be time earned. But this would be labeled in each cell as "8 Hrs" or "4 hrs". Column C would be time used in the same format "4 hrs" "8 hrs". Then Column D would simple be hours remaining.
Now in the second section I'd have holiday hours earned, which is 2 weeks. Not too sure how to lay it out, and then I still have my sick days, but not sure if I should include that in section 2 or not with the vacation time.
I'd like a way to be able to simply Calculate B2 - C2 = D2. So 8 Hrs - 4 Hrs = 4 Hrs (to show 4 Hrs remaining for each line item.)
Problem is I'm unsure how to calculate remaining time simply because of the Hrs suffix. And with that I also can't calculate total time still remaining, both for holiday hours earn and vacation/sick hours.
Yes, it's easier for me to track it as 8 Hrs rather than 1 day, etc.
Any advice on how to formulate this. Or if anyone knows of a premade template that fits this type of scenario, that I could then just take and integrate into my own spreadsheet.
Sorry if this is confusing in any way.
Also, As I'm no excel wizard, unsure if this is relevant or not, but I'm using Excel 2016, as part of the Office suite.
Another option is to just leave the number as it is and label the column accordingly. Do you really need to see "hrs" in every cell when you know you are tracking hours?
Use a custom number format of,
[>1]0 \H\r\s;[=1]0 \H\r_);0 \H\r\s;[Red]#
... and treat all hours as integers.

Get total days and Hours between 2 timestamps with excel

using excel 2013
I'm trying to get the total days and hours between current date/time and time stamp
using =NOW()-B3
And custom format
dd"-Days" hh"-hrs"
which gets me.
21/05/2015 12:45 00-days - 00-Hours
01/04/2015 13:23 18-days - 23-Hours
02/05/2015 13:45 18-days - 23-Hours
This is fine until a month is rolled over which will then give a wrong result. line 2 example. How do I get it to show total days.
many thanks
Use the DATEDIF function:
=DATEDIF(B3, NOW(), "d")
Unfortunately, this doesn't support hours AFAIK, so you have to combine it with your solution in order to get a combination of days and hours.
Try this... assuming your first example is written in A1:
=ROUNDDOWN(C1,0)&"-days "&TEXT(C1-ROUNDDOWN(C1,0),"hh")&"-hours"
oh yeah... use a regular number format in the cell that contains the formula.
Substract the two dates and you will have all the information you need, the integer part is the number of days, the decimal part gives you the hours.
Diff=Now()-B3
MYDAYS=Truncate(Diff)
MYHOURS=truncate((Diff-Days)*24)

Excel - Analyse the best weeks sales

If I had a better idea how to do this, I would have been more specific in the topic ;)
I have a list of repetivite sequencial dates in column A, and the profit in column B.
I'd like to analyse which sequencial 7 days have been the most profitable.
01/01/2013 10
04/01/2013 15
08/01/2013 12
08/01/2013 21
09/01/2013 18
13/01/2013 20
16/01/2013 14
19/01/2013 25
In this example the week commencing the 13/01/13 was the most pofitable with 59.
I have 4 years to anaylse of 3000 sales.
I really appreciate any assistance or starting point.
Add two more columns YEAR and WEEKNUM in the same sheet and do a pivot
Pivot :
I found the solution was possible using the following code:
=SUM(INDIRECT("$B$"&MATCH(A1,$A$1:$A$10,0)):INDIRECT("$B$"&MATCH(A1+6,$A$1:$A$10,1)))
Using the MATCH function I was able to find the first CELL for the sale of the day (01/01/13), and then the CELL of the final sale of the day +6 days in (04/01/13)
Then using the INDIRECT function I SUM the two cells together to give me the largest range of sales in any 7 day period.
Thanks to those that helped and suggested good starting points.
I would start by getting rid of duplicate days from the left column by adding their profits together.
Then perhaps you can apply some of the answers to this question: How to find maximum of each subarray of some fixed given length in a given array

What is wrong with this calculated field for total hours between two times in SharePoint 2007?

I am attempting to get the total hours between two times in a SharePoint 2007 list. Right now I have the formula as...
=INT(([Column2]-[Column1])*24)
...which I have looked up and says that it is the correct formula to do this. But, what I get is a weird date like "2/18/1900 12:00 AM" instead of what it should be: 26.
Another formula I tried was...
=TEXT([Column2]-[Column1],"h")
...but, this will only get the difference in hours and not count the days (if they are more than one apart).
Both of the columns are Date & Time columns. So, what am I doing wrong?
My take is that you set the output format of the calculated column to be Date and Time, while it should be of type number.
In a calculated column, the number of hours between two times is:
=TEXT([Column2]-[Column1],"h")
Providing that the difference is less than 24 hours. Otherwise, you'll need to look at getting the days difference and doing a multi-step calculation involving the number of days between the dates * 24 + the calc above.

Format a time span as a number of days, hours and minutes

This is purely an Excel sheet question.
I have a time span that is basically a difference between two cells, each containing a date:
I have managed to get the time difference in number of hours and minutes by changing the number format to [h]:mm. Now I would like to get the difference in number of days, hours and minutes. I tried to set the number format to [d]:[h]:[mm] but it is not accepted by Excel.
Here's what I have now:
A B C (=A2-A1)
---------------- ---------------- ----------
1| 14/10/2011 00:00 17/10/2011 07:50 79:50
2| 14/10/2011 00:00 17/10/2011 11:00 83:00
Here's what I would like to get:
A B C (=A2-A1)
---------------- ---------------- ----------
1| 14/10/2011 00:00 17/10/2011 07:50 3:7:50
2| 14/10/2011 00:00 17/10/2011 11:00 3:11:00
How can I do that? Is there a number format available for that?
You can use TEXT
=TEXT(B1-A1,"d:h:mm")
Note the same effect can be achieved using a simple number format on the cells directly
select your range (cells C1, C2 etc)
right click and Format Cells
Custom
Type d:hh:mm
If unlike your example data, your date differences exceed 31 days, then an approach such as
=INT(B1-A1)&":"&TEXT(B1-A1,"h:mm")
will work
Warning: the above only works for ranges less than 31 days.
use
=CONCATENATE(TEXT(FLOOR(B1-A1,1),"#")," Days",TEXT(B1-A1," h:mm:ss"))
instead for ranges above 31 days. This will not sort well, so it would be better to do the calculation in one column and then prettify that column for the end result.
Unfortunately it appears number and datetime formats cannot be combined, otherwise a custom format of:
0:h:m
would be the ticket. However, if for spans of 32 days or more, you are satisfied with just displaying the number of (fractional) days you can use a custom format like:
[>=32] 0.00 "days"; d:h:m
The cell value remains numeric.
The following is certainly not the shortest formula and not a direct answer to the question but works to show the correct result (also on LibreOffice) in the following format:
# days ## hours ## minutes ## seconds
=CONCATENATE(TEXT(FLOOR(B2-A2,1),"#")," days ", IF(HOUR(A12)-HOUR(A11)<0,HOUR(A12)-HOUR(A11)+24,HOUR(A12)-HOUR(A11))," hours ",IF(MINUTE(A12)-MINUTE(A11)<0,MINUTE(A12)-MINUTE(A11)+60,MINUTE(A12)-MINUTE(A11)), " minutes ", TEXT(B2-A2,"s"), " seconds")
The following approach works as well, assuming that your start date is in cell C2 and your end date is in cell D2:
=TEXT((D2-C2)-MOD(D2-C2,1),"0") & " days " & TEXT(MOD(D2-C2,1),"hh:mm")
=IFERROR(INT(Date1-Date2)&" Days "&INT(MOD((Date1-Date2);INT(Datw1-Date2))*24)&" Hours "&MINUTE(Fate1-Date)&" Min";IFERROR((Date1-Date2);"NA"))enter code here
I think this should do the trick, whatever date you have.
Had a similar kind of question, except for me, I needed hours divided by 8, instead of 24, as I needed working days. So I came up with a solution, but it's really really complex to understand because the code looks like a mess, but if you segment them, it's not that hard.
=CONCAT(INT(C16*24/8),":",IF(INT((C16-INT(C16))*24)<10,CONCAT("0",INT((C16-INT(C16))*24)),INT((C16-INT(C16))*24)),":",IF(MINUTE(C16)<10,CONCAT("0",MINUTE(C16)),MINUTE(C16)))
Note that I have used "8" to divide the hours by 8 because I needed working hours. So you can neglect that if you do not want it
I needed to display the result as "4:09:08" rather than "4:9:8". (This is in "Days:Hours:Minutes" format). That's why I have used extra IF() and CONCAT() functions inside.

Resources