how to get zulu time difference seconds/milliseconds in excel - 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.

Related

Converting decimals to [h]:mm:ss

I'm importing data from Excel to MATLAB. My data in Excel is in [h]:mm:ss format, but when after importing to MATLABthe data becomes a decimal number.
Is there a way to convert this data back to an [h]:mm:ss format in MATLAB?
Some examples:
21:45:05 equals 0.906307870370370
21:14:31 equals 0.885081018518519
213:17:56 equals 8.88745370370370
I understand the conversion being a multiple of 24h be it in seconds, minuites or hours - which would imply 12:00:00 = 0.5. But I don't understand how I could convert the data back, i.e. 0.75 becomes 18:00:00 etc?
I've tried New_Nun(i,j) = datestr(nun(i,j),'HH:MM:SS'); to do this conversion, but I get this error -
Unable to perform assignment because the indices on the left side are not compatible with the size of the right side.
Would this be because my nun variable has NaN's in?
Note that datestr outputs a string, while the New_Nun(i,j)=...assignment expects a single value.
datestr(nun(i,j),'HH:MM:SS') outputs a [8 x 1] char array, which will not fit into New_Nun(i,j). And, by the way, 'HH:MM:SS' is indeed the correct argument for hours, minutes and seconds.
You may rather use a cell for New_Nun, which can contain any kind of data including strings of arbitrary length :
%Initialize random values with a NaN
nun=rand([5 5]);
nun(2,5)=NaN;
New_Nun = cell(size(nun)); %Initialize the cell array
not_a_nan = ~isnan(nun); %Selection valid values
New_Nun(not_a_nan) = cellstr(datestr(nun(not_a_nan),'HH:MM:SS')); %Fill the cell array
disp(New_Nun)
'13:47:28' '23:37:19' '06:00:28' '13:24:09' '12:38:05'
'00:55:58' '08:34:58' '04:25:44' '11:14:46' []
'13:17:25' '10:34:02' '11:17:16' '04:42:18' '05:51:32'
'20:40:44' '18:30:16' '04:29:22' '17:43:03' '22:05:24'
'16:36:35' '10:17:18' '22:45:41' '16:04:17' '07:06:39'
The NaN value has been converted to an empty cell. It could be replaced with any default value, e.g. New_Nun(~not_a_nan)={'00:00:00'};
This code does not handle hours above 24, as datestr. For than, hours need to be treated separately.
%Initialize random values with a NaN and one value larger than 24h
nun=rand([5 5]);
nun(2,5)=NaN;
nun(3,4)=nun(3,4)+10; % One value above 24h
New_Nun = cell(size(nun)); %Initialize the cell array
not_a_nan = ~isnan(nun); %Selection valid values
mmss = cellstr(datestr(nun(not_a_nan),'MM:SS')); %Write only MM:SS
hh = floor(nun(not_a_nan(:))*24); %Get hours, and make it a column vector
%Now, add the hours
hours_not_zero = hh~=0; % Optional: used to display mm:ss if hh=0
mmss(hours_not_zero) = cellfun(#(h,m) sprintf('%02d:%s',h,m),num2cell(hh(hours_not_zero)),mmss(hours_not_zero),'uniformoutput',false);
New_Nun(not_a_nan) = mmss;
disp(New_Nun)
'02:53:42' '08:38:56' '12:07:03' '15:28:54' '12:49:18'
'16:21:15' '03:44:23' '01:22:31' '20:43' []
'02:36:04' '11:08:51' '19:51:35' '244:45:48' '33:55'
'16:14:08' '08:04:01' '12:27:22' '08:17:48' '06:16:15'
'10:41:08' '03:16:19' '04:47:15' '04:33:37' '20:36:42'
This time, the value 35:34:11 is represented correctly. Not significant hours are not displayed, such as '20:43' for '00:20:43'.

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

Time and date difference in 2 cells in Excel

I am having Excel with Date time stamp at random row in B Column,
Ex: Where in between cell are Empty ( B2, B3..etc).
B1 : 15:13:48:335 2014/08/06
B27: 15:13:55:955 2014/08/06
B31: 15:14:16:005 2014/08/06 ...
I need to find the time difference between 2 consecutive entries Ex: B21-B1 and B31-B27 and so on.
If the values you've shown are actual datetimes, then they are numbers that seem to grow progressively larger as the rows increase.
To get the difference from B1 to B27,
=LARGE(B:B, 2)-LARGE(B:B, 3)
Format the result as time in any way you prefer.
For the difference from B27 to B31,
=LARGE(B:B, 1)-LARGE(B:B, 2)
When datetimes are actual datetimes and not text, the LARGE function can be used just like any other number.
If your values in column B are text, start by reverting them to proper datetimes. Use something like the following,
=DATEVALUE(RIGHT(B1, 5)&"/"&MID(B1, 14, 4))+TIMEVALUE(LEFT(B1, 8)&"."&MID(B1, 10,3))
Correct your data first; then worry about manipulating the numbers.
If the cells propreties are correct, Excel should be able do compute a difference between them without any problem.
Both of the cells containing the dates must be set with Date/Hour format, the cell containing the result of the difference can be (for instance) set to Standard. Then the difference will be a number (integer or float). For instance :
If the result is 3, it means 3 days, multiply it by 24 to have the
number of hours.
If the result is 3,6667, the integer part gives you
the number of full days, the float part gives you the number of
hours. 0.6667*24 = 16 hours.
Hope it helped

Excel Convert text to timestamp

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.

Resources