Want to format a second to dd:hh:mm:ss to remove the zero values for readability in Excel 2016 - excel-2016

I have the solution to convert seconds to a correct value of xx Days yy Hours zz Minutes aa Seconds and I want to know a way to have the output drop the values and labels if the value is 00.
Have been looking through several sites and found all the great ways to manipulate the seconds to change the format but I suspect I will need a function to get the desired output.
Here is my code to convert seconds to correct format:
=TEXT(G2/(24*60*60),"dd \D\a\y\s hh \H\o\u\r\s mm \M\i\n\u\t\e\s ss \S\e\c\o\n\d\s")
60 (as my source seconds) comes across in the output as 00 Days 00 Hours 01 Minutes 00 Seconds. I want it to say 01 Minutes with the other values removed. 12600 (as my source seconds) comes across in the output as 00 Days 03 Hours 30 Minutes 00 Seconds. I want it to say 03 Hours 30 Minutes with the other values removed.

You'll have to use =Concatenate(If(......)) to achieve this.
Just for the demonstration, I added 4 more columns, each for day, hour, minute and second and then concatenated them into one.
My data is at cell C2. And formulae are below :
Cell H2 : =TEXT(C$2/(24*60*60),"dd")
Cell I2 : =TEXT(C$2/(24*60*60),"hh")
Cell J2 : =TEXT(C$2/(24*60*60),"mm")
Cell K2 : =TEXT(C$2/(24*60*60),"ss")
The above four will just extract the actual number of day/hour/minute/second. And the following four will add suffix to it based on whether the value is zero or non-zero.
Cell L2 : =CONCATENATE(IF(H2<>"00",CONCATENATE(H2," days"),""))
Cell M2 : =CONCATENATE(IF(I2<>"00",CONCATENATE(I2," hours"),""))
...
...
Finally, just concatenate L2 through O2 to achieve desired result.
=CONCATENATE(L2," ", M2," ",N2," ",O2)
You might want to download the demo implementation from here.

Related

Going more than 24hrs and adding days

I have an expression in a table that is calculating the total of the column that has different times in it. But after the total goes over 24 hours it resets. I want to add to have days also in it if it goes more than 24hrs. I have so far added days in the format but this means that even with 0 days it gives 01 days since it is using the days section of the date. This is wrong and I either want to take one away from this ot have some sort of a counter to count the days. This is the expression if have so far:
=format(DateAdd("s", SUM(Fields!TotalDowntime.Value), "00:00:00"), "dd 'days' HH 'hrs' mm 'mins' ss 'secs'")
I have tried to format and using dateadd function to see if this can be done in a different way
The following isn't a full answer, but I'm hoping it will help you towards one. I think I've understood from your question that the field which records your TotalDowntime figure records this value in seconds.
SELECT
TotalDowntime/(24*60*60) as [days],
TotalDowntime/(60*60) % 24 as [hours],
TotalDowntime/(60) % 60 as [minutes],
TotalDowntime % 60 as [seconds]
FROM
MyTable
You'll see that all the parts simply cut off any decimals that result from the division. The % is SQL Servers "Mod" function that returns the remainder on division.
You should be able to put code similar to the above "server side" and concatenate these columns in reportbuilder (or server side if you wish).

Show zeroes if right two digits are zero

I am having trouble solving this one. If i have the following values stored in U_pmHours
3.00
4.25
5.50
The following code correctly gives me the two digits after the decimal place
RIGHT(FORMAT(CONVERT(DECIMAL(4,2),T2.U_pmHours)/2,'N2'),2) AS 'TEST 2'
So the new values will be
00
25
50
The problem i am having is converting these values to minutes using * 60 /100, it works as it should on everything that isnt 00, instead of still showing 00 it shows as blank.
What can i do to make it either not do the calculation if the digits after the decimal are 00 (3.00) or to still show 00 in this case.
This has been solved. My problem was that I was trying to use two different field types in the same column. On one end i was performing a calculation for one instance and then providing a string for the other.
I resolved this by simply converting the calculated part of the code to also be a varchar type.
CASE WHEN
SUBSTRING(CONVERT(VARCHAR,CAST(T2.U_pmHours AS DECIMAL(4,2)) / 2),3,2) = '00'
THEN '00'
ELSE
CAST(SUBSTRING(CONVERT(VARCHAR,CAST(T2.U_pmHours AS DECIMAL(4,2)) / 2),3,2) * 60 / 100 AS VARCHAR)

Checking against a threshold and calculating the time duration

I have a DataFrame as follows:
Timestamp Signal
2020-01-01T10:25:44.000 - 6.00 20
2020-01-01T10:25:45.000 - 6.00 15
2020-01-01T10:25:46.000 - 6.00 8
2020-01-01T10:25:47.000 - 6.00 17
2020-01-01T10:25:48.000 - 6.00 19
2020-01-01T10:25:49.000 - 6.00 19
The timestamp column is a string and not converted to datetime. I want to compare the signal values against a threshold, for example 12 and calculate the time duration the signal stays above 12. So for the given dataset, the duration values will be [2,3] in seconds returned as a list/array. How do I do that in Python? Any help is appreciated.
If it is guaranteed that there will be a row for every second, then you can try to count the rows instead of getting a difference in timestamps.
Either way you need to identify consecutive rows above your threshold.
df['above'] = df.Signal.gt(12)
df['stint'] = (df.above.diff().fillna(0) != 0).cumsum()
# above is a boolean, so diff() will get +1 when stepping above 12 and -1 when stepping below
# !=0 will mark each step up/down with True
# cumsum() will create a 'stint ID' of sorts, so we can groupby it
Now, we can parse timestamp with df.Timestamp = pd.to_datetime(dfTimestamp) and get the difference between each step OR in this case it seems easier to just
stints = df.groupby(['stint', 'above']).Signal.size()
stints = stints.loc[stints.above==True]

Excel logic - matching columns

My situation is the following:
The 'Day' column is 1 to 365, and each day is repeated 24 times (for the 24 hours). Each day and hour together have a Degree value, represented by the B column. I need to multiple the B column with the E column everytime A column matches D (eg. B2*E2, B3*E2, B4*E2, B7*E3).
How can I do that? I'm really confused here.
Thank you
Using your shown example, in cell C2 and copied down:
=B2*VLOOKUP(A2,$D$2:$E$366,2,FALSE)
Two ways:
VLOOKUP(A2,$D$2:$E$366,2,FALSE)*B2
SUMPRODUCT(B2*($D$2:$D$366=A2)*$E$2:$E366)

How can i add minuts in current Datetime in excel with the help of formulla?

I have a excel sheet in which i want to add 10 minute.
Example of output as :
Actual Time is : 10/2/2013 12:30:00 , so in this time i want to add 10 minute so i need output as 10/2/2013 12:40:00.
Please provide me formula for this.
Many Thanks,
Tausif.
The answer is covered in Excel Help:
if you use the TIME function, then =A2+TIME(0,10,0) will add 10 minutes to the time in cell A2; +TIME(1,0,0) adds 1 hour, etc.
Try this: (assuming your date data is in the C3 cell)
=C3+TIME(0,10,0)
The first parameter is for hours, second is for minutes, third is for seconds.