Convert elapsed time to numeric in crystal - crystal-reports

i got a question :
How can i convert an elapsed time like 835:0:44
to numeric for summing and average ?
i tried things like instr and then tonumber and then avergae the outcome.
but i miss the minutes and seconds then.

Related

How to calculate fraction in datediff function in Tableau

I am not really an expert in Tableau. I have a need to calculate a timedifference in hours, but also want to see fraction of an hour. I am using Tableau 9.
I used the function
IF DATEDIFF("hour", [CL2_Start_Time_ST], [CL2_End_Time_ST]) > 8 then NULL
ELSE DATEDIFF("hour", [CL2_Start_Time_ST], [CL2_End_Time_ST])
END
If the time difference between CL2_Start_Time_ST and CL2_End_Time_ST is less than 1 hour (for example 30 minutes) the result is 0, but I want to see 0.5 in result.
I dont want to calculate in time difference in minutes since all my other calculations are in hours and hence it is easier to create a relative plot with other calculations.
Please help.
I found the answer to the above question. The simple formula below worked. I was using DIV function and that caused the issue.
IF DATEDIFF("hour", [CL2_Start_Time_ST], [CL2_End_Time_ST]) > 8 then NULL
ELSE (DATEDIFF("minute", [CL2_Start_Time_ST], [CL2_End_Time_ST])) / 60
END

How to do calculation on time values imported from Excel?

I have the following values in Excel:
Bed time 19:34:00
Get up time 07:04:00
Time in bed 11:30:00
Sleep start 19:42:00
Sleep end 07:00:00
I want to import them into MATLAB and do some calculation on these time values such as subtraction. The time values look like this after importing:
0.8153
0.2944
0.4792
0.8208
0.2917
and obviously doing calculation on them would be nonsense. Would any body help me with this issue? I have stuck with it for few days, and no progress yet.
Thanks in advance,
As assylias pointed out, these are fractions of days. You can use the datestr function to convert it to human-readable strings with formatting option conveniently.
e.g.:
datestr(0.2917, 'HH:MM:SS')
ans =
07:00:02
Calculations such as subtractions can be done on the raw values before
conversion.
E.g: get duration of sleep.
start = 0.8208
stop = 0.2917
datestr(stop-start, 'HH:MM')
ans =
11:18
Even works for intervals that span over midnight.

Calculating seconds in MATLAB

I have a code that calculates power consumption of devices in Watts. I need to calculate the KWH usage of that device in that month and i have a formula that looks like this
( Watt Usage * Hours/Day * Days/Mo. ) / 1000 = Kilowatt Hours used that month
I have the Watt Usage,but having trouble with tracking time.So is there a way to calculate seconds so that i can use it to calculate hours,days and unit consumption.
MATLAB has some tools for manipulating with time:
clock:
t=clock; % returns a six-element vector containing the current date and time in decimal form, ( i.e. [year month day hour minute seconds] )
date :
d=date; returns a string containing the date (in dd-mmm-yyyy format).
also , you can use tic and toc to measure elapsed time between two moments.(like a stopwatch)
tic;% starts the stopwatch
% after some time
toc % returns elapsed time

Matlab convert date string to timestamps using datenum problems

I am new to Matlab. I am trying to use datenum function to parse date string and convert to timestamps(like in Java, getTime()).Then, I want to find out the difference between two dates in seconds.
datenum('2013-02-21T00:39:19Z','yyyy-mm-ddTHH:MM:ss')-datenum('2013-02-21T00:34:19Z','yyyy-mm-ddTHH:MM:ss')
If I run the function above, I get 0.0035 which I have no idea what kind of value it is.
Can someone help please?
Thanks!
Matlab help says:
A serial date number represents the whole and fractional number of
days from a fixed, preset date (January 0, 0000).
I reckon your answer is maybe 0.0035 days so to get seconds I guess its
ans*24*60*60
Your result is in datenum format as Dan says. But if you want to find elapsed time in seconds, there is a function that does exactly what you want.
You can use etime to find elapsed time between two date vectors.
d1 = datevec('2013-02-21T00:39:19Z','yyyy-mm-ddTHH:MM:ss');
d2 = datevec('2013-02-21T00:34:19Z','yyyy-mm-ddTHH:MM:ss');
elapsedTime = etime(d1,d2) % Elapsed time in seconds
elapsedTime =
300

datetime format in matlab

I have some data that was given to me in excel and the time format is rather confusing. The fist column of the is the DateTime but with incorrect HH:MM and the second column is the correct hour of the day HH:MM:
time = {'01/01/2000 00:00',num2str(2300);
'01/01/2000 00:00',num2str(2400);
'01/01/2000 00:00',num2str(10);
'01/01/2000 00:00',num2str(100)};
However, when the time exceeds midnight, instead of being 00:10 the time is 10, and 01:00 is 100. How could I alter these to the correct format? i.e. from the example above I would like the outcome to be:
time = {'01/01/2000 23:00';
'01/01/2000 24:00';
'01/01/2000 00:10';
'01/01/2000 01:00'};
How could I achieve this?
Using sprintf in MATLAB, you can use the field width specifier:
where
Field width:
Minimum number of characters to print. Can be a number, or an asterisk (*) to refer to an argument in the input list. For example, the input list ('%12d', intmax) is equivalent to ('%*d', 12, intmax).
Thus your times should end up all looking like "XX:XX", with the leading zero added by the sprintf if it is missing and the colon added in.
Thanks to #Junuxx for the exact command: sprintf('%02i:%02i', hours, minutes)
To separate hours and minutes, you would obviously do time % 100 to get the minutes and integer divide by 100 to get the hours.
From there, you simply strcat or concatenate ["a" "b"] your two columns to get your desired result.