Summing time in Excel table gives very large number? - excel

Can anyone help please?
When I sum two time value such as 09:00 and 22:30 I can get a result of 31:30 by formatting the cell using [h]:mm:ss.
However, whenever I try and do this with a subtotal row on an Excel table, it’s gives ridiculously large numbers?! For example, if I do the same as my first example, I get a result of something like 2million?!
Can anyone explain what I’m doing wrong? It works fine outside of the table but I need to use a table since I am populating the values from a PowerAutomate flow.
As above please see my example

Excel uses numbers to represent dates and times. It starts with 0.0 as midnight on Jan 1 1900 , 1.0 is midnight on Jan 2 1900 etc, each whole number is one day since Jan 1 1900 and times are represented using a fractional value. E.g. 0.5 is noon on Jan 1 1900, 2.25 is 6:00:00 am on Jan 3 1900 and so on.
When you sum date-times in Excel , it just sums these numerical values.
In your test case of adding two date-times 9:00am and 22:30 (=10:30pm) and getting 31:30, you are probably summing two fractional values only (e.g. 0.375 + 0.9375 ) to get a whole day and a bit ( = 1.3125) which the format you are using shows you 31:30.
Typically, date-times in Excel are both the whole number and the fraction. For recent dates these numbers can be quite large 44,926.5 is noon on Dec 31st 2022 for example. If you sum even a few of these, as numbers, and try to represent them as dates you will get an absurdly large number.
In order to help you better you will need to tell us the actually numerical value (not the formatted representation) of the underlying cells.

Related

How to convert custom digits to date in excel

Assuming 421 stands for April 2021 and 1299 for December 1999, what would be the correct formula to convert the digits in to the corresponding date format in excel?
Adjust the 30 as you see fit:
=IFERROR(DATE(IF(VALUE(RIGHT(A1,2))<30,2000+RIGHT(A1,2),RIGHT(A1,2)),LEFT(A1,LEN(A1)-2),1),"")
Actually, here is a one-liner (note, to get the correct century the formula is posted lower in the answer and is more complicated):
=DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1)
DATE requires 1) Year 2) Month and 3) Day
So, it's easy to get the year (just take the two most digits)
However, it's trickier to get the month, since it can be 3 or 4 digits, so you need some if logic to add a 0 in front if only 3 digits and THEN take the left two digits to extract the month.
Finally, you have to have a day for the formula, so just put a 1. Then format the cells as desired to whatever date format. See screenshot.
In order to get the correct century, then the formula gets complicated :) Basically, it says if the date is greater than now, subtract a century. If it is less than now, then go with that date.
=IF(DATE(YEAR(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1))+100,MONTH(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1)),DAY(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1)))>NOW(),DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1),DATE(YEAR(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1))+100,MONTH(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1)),DAY(DATE(RIGHT(A1,2),LEFT(IF(LEN(A1)=3,0&A1,A1),2),1))))

Difference between date and time w/out work week Excel

I am trying to determine the amount of time a procedure takes. I have the Start Date and Start Time as well as End Date and End Time. What I need to do is display the result in hours:minutes:seconds BUT I need to use a 7 day work week rather than a 5 day work week. Here is a sample data point:
Cell A1 and C1 are both formatted as short dates. Cell B1 and D1 are formatted as times. The formula in E1 is =((C1+D1)-(A1+B1)) and E1 is formatted as a custom number [h]:mm:ss . The problem I am having is calculating through a weekend. The times just don't add up and I think it is because of the type of work week that Excel uses.
Any help is appreciated, thanks!
First, you need to know / understand that any number is a potential date / time for Excel and that Excel knows only datetime (and not date and time separately).
Here is why: anything before the decimals-placeholder are the days since December 31, 1899. So, the number 42,000.00 is also a date. It is the 42.000th day after December 31, 1899 which is December 27, 2014.
Anything after the decimal-placeholder is considered a fraction of a day. So, the value 0.5 is half a day and therefore the time 12 noon while 0.75 is 6 in the afternoon (pm).
Hence, all of the dates you are showing in your above examples may have also times associated with them and all the times you are showing might also have a date associated to them. Just change the number format on all of these cells to general numbers and you should see only Integer values for the dates (without any decimal places) while all the times should contain only be a fraction of 1 and should all have a 0 before the decimal-placeholder.
If that is not the case, then you have just found your culprit.
With the above knowledge it is also easy to calculate the difference between two dates or times. The difference is a simple addition or subtraction: 42,000.00 + 100 + 0.5 = 100 days after December 27, 2014 at 12 noon = April 6th, 2015 # noon. So, you can just add the numbers and subtract them as you have done. If you wish to subtract two days to account for a weekend then you can simple subtract 2.
Now, let's have a look at your above example:
June 23, 2016 converts to 42,544 while 07:41 in the morning converts to 0.32. So, we have here 42,544.32 while the ending datetime converts to 42,545.47.
The difference is calculated correctly as 1.15. That means that there is a difference of one day and the fraction of a day of 0.15 * 24 (hours in a day) = 3 hours and 36 minutes.
I guess the real problem you are having is to show the result correctly. If you show it as a date then it is one day after December 31, 1899 = January 1st, 1900. If you show the result as a time then you only get to see the 03:36:00. The best is probably to show the difference as a number only as 1.15. If you want to see the result differently then you will have to adjust the resulting view to your needs. For example:
= 1.15 * 24 = 27.6 hours difference between the start date/time and the end date/time.
Let me know if you have any further questions.

Formula to get the worked hours from time A to time B where B is past midnight

I'm using Excel to write down my shifts and get a total of worked hours per day and per week.
I structured it this way:
Everything seemed to work fine until I finished to work at 12.30 am. The result with my formula was -17 hours instead of 7. How can I fix my formula so that it displays a correct amount? I'm using the following formula and I want the result to be displayed in number format, not time.
=IF(C11=0,0,IFERROR(((C11-B11)-D11)*24,0))
What formula can I use?
Excel treats days as 1 for every day past Dec 31, 1899. Today happens to be 42,217. Time is nothing more than a decimal portion of a day. Today at noon was 42,217.5 and tomorrow at 03:00 will be 42,218.125.
Excel also treats boolean (e.g. TRUE/FALSE) values as either 1 or 0 when used in a mathematical equation. e.g. 0.5 + TRUE = 1.5 while 0.5 + FALSE = 0.5.
Test to see if the minuend is less than the subtrahend and if it is, add 1 to it using the result of the test itself.
=(C11+(C11<B11)-B11)*24
      
Finally, it should be mentioned that while you can subtract a larger time from a smaller time to receive a negative decimal value, the negative value cannot be interpreted as time since Excel does not recognize negative time. If you were not multiplying by 24 to retrieve the hours as integers and simply subtracting B11 from C11 the cell would be filled with hashmarks (e.g. ############) to show the error. e.g. 08:00 - 10:00 = (as time) #######.

Timestamps, majorating and sum

I'm with a problem doing a part of a program, I hope you can help me.
I have this three columns in excel;
01-01-2012 00:15 A 7,160000
01-01-2012 00:30 A 1,600000
01-01-2012 00:45 C 3,040000
01-01-2012 01:00 A 1,560000
01-01-2012 01:15 A 0,000000
01-01-2012 01:30 D 0,000000
01-01-2012 01:45 A 0,000000
t goes until 31-01-2012 23:45
And now I want to read them into MATLAB and convert them into 3 new matrix with this format;
Timestamp
01-01-2012 00:00
01-01-2012 01:00
(...)
Period
A
A
Price
11,800000
10
So basically I want a program that read's timestamp and keep's day month year and hour (ignoring the minutes), for that period of time it needs to show the most repetitive value in periods of one hour (for example: it will give A to 00 and C to 01) and finally I want it to sum the prices for that hour (so it will sum the price at 00:15 + price at 00:30 etc.)
It will be a huge help, if you can solve me this problem.
P.S In the 1 hour periods I will always have one most repetitive marker (3 of A and 1 C, 3 D and 1 A etc.) I could find in this month 4 markers, A B C D. This markers aren't cyclic but I will find it all across the month.
It seems to me like your main issue is reading the data from Excel and get it in a format you can work with. If so:
Check out xlsread. You have a lot of possibilities there. You can for instance use the following syntax:
[num,txt,raw] = xlsread(___)
but if you are new to MATLAB and don't require the most efficient way, I would recommend you to read each of the columns separately. Note: This is not the best way, but it's the easiest way in my opinion. You can use this command on each of the columns (thus calling it three times):
num = xlsread(filename,sheet,xlRange)
Check out this page to see how you can handle the dates. In summary, convert the dates to numeric values in Excel. Since you have hours and minutes, this will be a decimal number representing the number of days since Jan 01, 1900 (or Jan 02, 1904 if on MAC). Since MATLAB counts from Jan 01, 0000, you need to add some 1900 years after reading the file (check the reference I gave to see how).
One way to handle that you don't want minutes is to convert to datevec, and zero out the last columns (this way you will also remove the information):
[Y, M, D, H, MN, S] = datevec(___) ;
% or
date_vector = datevec(___);
% Where you just don't use the MN and S variables
If you want the dates looking like dates, convert the datevec to datestring. Check out formatOut, and you can choose the format you want.
Try out the above. I'm afraid I can't do that work for you.
To get the most repetitive values, check out mode. mode(X) returns the sample mode of X, which is the most frequently occurring value in X. You can also replicate this functionality by combining some of the following: sort, unique, diff or all. And you can of course use sum to sum the values.
If it's only the last part here your stuck on, I suggest you rephrase the question a bit. If it's both, and you get stuck on the last part after doing the above, I suggest you ask it as a separate question, as that won't be related to reading it from Excel.
Good luck =)

Basic excel date and time problem

Have a list of dates in excel in the format (this comes originally from csv):
23/11/09 07:27:02
23/11/09 08:01:50
23/11/09 08:38:58
23/11/09 09:40:01
What I want to do is count the number of these falling between hour blocks, like 7-8, 8-9, 9-10 etc
Not sure how to get started, but one idea was just to put logic statements comparing the dates between these blocks, then adding the total "trues"
I can't get it to compare properly. When I type it the hour block marks,
e.g. 23/11/09 08:00
excel actually shows that as
23/11/2009 8:00:00 AM
and the compare doesn't work. Well actually it does the opposite of what it should.
that is:
=IF(C5>L1,IF(C5<M1,TRUE,FALSE),FALSE)
C5 being date in top codeblock, L1 and M1 being the hour blocks I manually entered in the second code block.
Has anyone got any ideas?
=hour(a1)=7
will return true if the time of the date/time value in cell A1 is between 7 and 8 (AM) and will otherwise return false.
Excel stores dates as number of days since 1900 or 1904 depending on your setting and the time as a fraction of the days. So 11:59 am 4th of July 1960 is held internally as '22101.4993055556'.
As such you cannot do plain charactrer string comparisons on dates. However ther ar lots of nifty time/date functions available to you.
You probably want :
=IF(HOUR(B1) > 8,IF(HOUR(B1)<12,"YES","NO"),"NO")
You should use Excel functions, like HOUR(), to extract the parts of the times, and apply the logic tests to those extracted values.

Resources