Excel Convert text to timestamp - excel

I have the following text timestamp in cell A1. 22-OCT-13 03.40.00.000000000 AM. In B1 I have the following formula: =TIME(HOUR(MID(A1,11,2)),MIN(MID(A1,14,2)),SECOND(MID(A1,17,2))).
It yields 12:40 AM. The hour function returns zero, but the minute function works fine. I can't figure out what's up with it.

MIN is the 'minimum' formula that returns the smallest value out of a list of values, not the MINUTE formula.
I think you are not familiar with TIME(), HOUR() or MINUTE().
TIME() takes 'normal' values and converts them into a time value. If you have TIME(H, M, S), H is the number of hours (not a timestamp), M is the number of minutes (not a timestamp either) and S is the number of seconds (yet again, not a timestamp).
HOUR() takes a time value and extracts the hour from it.
MINUTE() and SECOND() are similar to HOUR(). What you probably meant to have is:
=TIME(MID(A1,11,2),MID(A1,14,2),MID(A1,17,2))
When you use MID() you are getting a number, not a timestamp. So, HOUR takes that number, interprets it as a timestamp and return the hour. In your example, the first MID returns 03. In excel, if you convert that to a timestamp, you get 03/01/1900 00:00 (in dd/mm/yyyy hh:mm format) and the hour is thus 0.
EDIT:
By the way, you could use this formula if you want to keep the date and time (not forgetting the AM/PM at the end:
=SUBSTITUTE(SUBSTITUTE(A1,".",":"),":",".",3)*1
The original date/time is almost one that can be understood by Excel. Replace all . with : and then replace the 3rd (last) : by . and multiply by 1 to tell Excel to convert that to a number. Just format the result as time and that should do it.

Related

Is there an excel function that I can use to give values based on what the time value is?

I'm looking for a function I can use that returns "Night Off Prime" if the time a programme was on was between 11pm - 5:59am, "Day Off Prime" if it was on between 6am - 5:59pm and "Prime" if it was on between 6pm - 10:59pm.
I've tried using the IFS function with the code being =IFS(OR(G3>=23,G3<6),"Night Off Prime", OR(G3>=6,G3<18),"Day Off Prime", OR(G3>=18,G3,23),"Prime")
The G column is just the hh format of the hour it was on, with the values formatted as Number.
I've also tried =IFS(OR(BK3>=23:00,BK3<06:00),"Night Off Prime", OR(BK3>=06:00,G3<18:00),"Day Off Prime", OR(BK3>=18:00,BK3,23:00),"Prime")
Here the BK column is the time the programme was on in the hh:mm time format
The main trouble I'm finding there is how to label time between two different times such as between 11pm - 5:59am instead of just past 11pm. I used the OR logical but that doesn't seem to have worked.
I've also tried a VLOOKUP function =VLOOKUP(BK2,$AC$899:$AD$901,2, TRUE)
Here the table array is
AC899 Night Off Prime AD899 23:00-05:59
AC900 Day Off Prime AD900 06:00-17:59
AC901 Prime AD901 18:00-22:59
If you prefer the IFS you may want to adjust like this (should work in the similar way for hh:mm as well):
=IFS(G3<6;"Night Off Prime";G3<18;"Day Off Prime";G3<23;"Prime";TRUE;"Night Off Prime")
(may replace ; with , depending on regional setting)
alternatively:
=IFS(G3<0;"#N/A";G3<6;"Night Off Prime";G3<18;"Day Off Prime";G3<23;"Prime";G3<24;"Night Off Prime";TRUE;"#N/A")
"The main trouble I'm finding there is how to label time between two different times such as between 11pm - 5:59am instead of just past 11pm."
Add a column H2 = G2 + 1/24
Then your ranges are 0 to 7/24, 7/24 to 19/24 and 19/24 to 24/24, so you don't have an interval split over a resetting of the clock to zero.

how to get zulu time difference seconds/milliseconds in excel

The excel column contains Zulu Timzezones How to calculate the difference between two dates in seconds.milliseconds
From Time 2022-04-25T04:16:57.823121842Z
To Time
2022-04-25T04:16:58.173194593Z
2022-04-25T04:16:58.089133751Z
2022-04-25T04:16:58.462278784Z
2022-04-25T04:16:57.829376293Z
2022-04-25T04:16:57.961790312Z
2022-04-25T04:16:58.445884586Z
2022-04-25T04:16:57.830806273Z
2022-04-25T04:16:58.067723338Z
2022-04-25T04:16:58.470913276Z
2022-04-25T04:16:57.838787068Z
When I Try to Do something like =B13-B14
Error
Function MINUS parameter 1 expects number values. But '2022-04-25T04:35:59.092943356Z' is a text and cannot be coerced to a number.
Converted to Number format
REVISED: I forgot to convert the milliseconds
You can convert the date strings into time values by breaking them into parts:
=DATEVALUE(LEFT(A2,10)) + TIMEVALUE( MID(A2,12,8) ) --MID(A2,20,10)/24/60/60
Where A2 is the date string.
This assumes that they have the exact structure that you have shown and fully padded with zeros. If that is not the case, for example the milliseconds could be .095Z, then you can mod this to:
=DATEVALUE(LEFT(A2,10)) + TIMEVALUE( MID(A2,12,8) ) --MID(SUBSTITUTE(A2,"Z",""),20,999)/24/60/60
to be safe.

Converting large time format to decimal in excel

I'm trying to convert a large time value in excel to a decimal number for hours.
I currently have a column adding up "Ready time" for a call centre which is 3545:20:02 as a SUM. I now want that to show me the same hours in a decimal format e.g. 3545.333 as it's used in another calculation.
For reference, when I convert the above time to a General excel value, it is 147.7222454.
The formula I've been using is: =IFERROR((DAY(M54)*24) + HOUR(M54) + (MINUTE(M54)/60),0) and has been working fine for smaller time values.
Thanks in advance!
Excel counts in days (1 day = 1) so for hours you just multiply by 24, i.e.
=M54*24
format result cell as number with required number of decimals
[the reason your current formula fails is because of DAY function - DAY is day of the month so it fails for you when the time value is >= 32*24 = 768 hours]

Convert time string from unix time command like 10m20.5s into time format in excel

I have time data from the unix time command like
203m53.5s
I have this data in excel. I want it to be converted to Excell time format so I can do mathematical operations like sum and averages over them.
How can I do this
Replace the m with : and the s with "":
=--SUBSTITUTE(SUBSTITUTE(A1,"m",":"),"s","")
Now that the time is in a format that Excel will recognize we need to change it from string text to a number. The -- is forcing the string into a number by performing a mathematical process of multiplying -1 * -1 to it.
It can be replaced by TIMEVALUE()
Then format the cell with a custom format of:
[mm]:ss.0
One way is to use a forumala to strip out the m and s and use those values for time in a new column in Excel.
Assume the Unix data is in column A.
=(LEFT($A1,FIND("m",$A1)-1)*60+MID($A1,FIND("m",$A1)+1, LEN($A1)-FIND("m",$A1)-1)/84600
then format the cell as custom and choose the time without the AM/PM
Breakdown:
(get the minutes by finding "m")
multiply by 60 to convert to seconds
+ (get the seconds by starting at the location of m, +1 to the location of m-length of the whole string)
-1 to account for the actual "s"
Then divide the whole thing by 84600 to convert to time as a decimal

Hours Calculations in Excel 2010

I have an Excel 2010 workbook which contains a cell with the value of, say, 9876:54:32 (manually entered) representing 9876 hours, 54 minutes and 32 seconds of, say, phone talk time.
Then I have a cell with the value of, say, 1000 (manually entered) representing 1000 calls.
I want to divide the values to get the average talk time of 592.615 minutes per call.
I'm doing a regular =A1/B1 and it gives me an error.
* EDITED *
Thanks Brain Webster for correcting my math. I mean 9.876 hours. But the point is that Excel gives me an error, not my manual math. Playing around with it I discovered that Excel is fine with me with values up to 9999:59:59. Once I try with 10000:00:00 and up, it doesn't recognize it as a time value.
I love these seemingly easy riddles, so here is my solution as a formula and as a VBA attempt:
my original:
= (LINKS(A38;FINDEN(":";A38)-1)/24)+ZEITWERT("0"&RECHTS(A38;LĂ„NGE(A38)-FINDEN(":";A38)+1))
translated:
= (LEFT(A38,FIND(":",A38)-1)/24)+TIMEVALUE("0"&RIGHT(A38,LEN(A38)-FIND(":",A38)+1))
This will get you the right value to a given 10k text of a time duration. You would only have to setup the format of the cell to [h]:mm:ss. Then those values will look the same, but one would be a string and the other a number - and that is a major difference ;)
In vba it looks much more easier, and once defined, you can use it as a worksheetfunction.
Public Function GetDurationValue(ByVal strInput As String) As Double
Dim arrResult As Variant
arrResult = Split(strInput, ":") 'saves you parsing
GetDurationValue = (arrResult(0) / 24) + _
TimeSerial(0, arrResult(1), arrResult(2))
End Function
A38 = "10971:12:14"
=GetDurationValue(A38)
=457.13349537037
You can use LEFT and RIGHT function to retreive parts of the time value and then sum and multiply these values by 60 [minutes] (resp. 3600 [hours]).
Something like this for the hours, minutes, seconds (A1 is the cell with time value):
B1=VALUE(LEFT(A1;FIND(":";A1)))*3600
B2=VALUE(LEFT(A1;FIND(":";A1; FIND(":";A1))))*60
B3=VALUE(LEFT(A1;FIND(":";A1; FIND(":";A1; FIND(":";A1)))))
Now you can sum that:
C1=SUM(B1;B2;B3)
Then divede by calls count (A2 is the cell with the calls count):
D1=C1/A2
Finally format it like time:
E1=TEXT(D1/(24*3600);"d \day\s hh:mm:ss")
BTW: I tried that in Excel 2013 and when I enter 111:22:33 into a cell it automatically converts to a time. So then I can divide it like you try...
It appears that hours > 10000 are not recognised as such by Excel. Therefore we need to introduce an IF() to see whether this is the case and determined the alternative formula for the case where hours >10000
=IF(ISERROR(FIND(":",A2)),A2/B2, <SCRIPT IN CASE OF >10000>)
<SCRIPT IN CASE OF >10000> will now be:
VALUE(LEFT(A2,FIND(":",A2)))/24+VALUE(LEFT(A2,FIND(":",A2, FIND(":",A2))))/(24*60)+VALUE(LEFT(A2,FIND(":",A2, FIND(":",A2,FIND(":",A2)))))*(24*60*60)
combine and enjoy!
Assuming you don't exceed 100,000 hours in A1, and you always display hours, minutes and seconds then this formula should suffice
=IFERROR(A1/B1,(LEFT(A1)*10000/24+RIGHT(A1,10))/B1)
format result cell as [h]:mm:ss to get the result as a time value
With 10971:12:14 in A1 and 1000 in B1 that should give a result of 10:58:16 [or format result cell as [m]:ss to get minutes and seconds like 658:16]
This version will work with any number of hours and with or without seconds
=IFERROR(A1/B1,(LEFT(A1,FIND(":",A1)-1)/24+RIGHT(A1&IF(COUNTIF(A1,":*:"),"",":00"),5)/60)/B1)

Resources