I have a data-set that has time (hours) data in it.
The time data is given as 0.1123, 3.1565, 0.2951 etc (all in hours).
How do I convert it into standard hours and minute format?
We can achieve this using two methods
1.Change to Date & Time
Once the data has been imported in Tableau. Change the data type of the column to "Date & Time". Tableau data engine automatically understand the time format and change the decimal time to Actual time
Refer this Image
2. Using Calculated Field "MAKETIME"
MAKETIME Requires three argument(hour, minute, second).Below code parse decimal number "3.1545" as
3 hrs, 9 min (0.15*60) and 16 sec (0.0045*3600)
MAKETIME(INT([DecimalTime]),
int(INT(([DecimalTime]100)%100).6),
int(INT(([DecimalTime]10000)%100).36))
Floor([value]) = the number of hours
Floor([value] * 60) % 60 = the number of minutes
Floor([value] * 3600) % 3600 = the number of seconds
Related
This question already has answers here:
Counting values by day/hour with timeseries in MATLAB
(3 answers)
Closed 6 years ago.
I have a year's worth of data, the data is recorded one minute intervals each day of the year.
The date and time was imported from excel (in form 243.981944, then by adding 42004 (so will be for 2015) and formatting to date it becomes 31.8.15 23:34:00).
Importing to MATLAB it becomes
'31/08/2015 23:34:00'
I require the data for each day of the year to be at hourly intervals, so I need to sum the data recorded in each hour and divide that by the number of data recorded for that hour, giving me the hourly average.
For some reason the data in August actually increments in 2 minute intervals, data for every other month increments in one minute intervals.
ie
...
31/07/2015 23:57:00
31/07/2015 23:58:00
31/07/2015 23:59:00
31/08/2015 00:00:00
31/08/2015 00:02:00
31/08/2015 00:04:00
...
I'm not sure how I can find all the values for a specific date and hour in order to work out the averages. I was thinking of using a for loop to find the values on each day, but when I got down to writing code realised this wouldn't work the way I was thinking.
I presume there must be some kind of functions available that would allow for data to be filtered by the date and time?
edit:
So I tried the following but I get these errors.
dates is a 520000x1 cell array containing the dates form = formatIn.
formatIn = 'DD/MM/YYYY HH:MM:SS';
[~,M,D,H] = datevec(dates, formatIn);
Error using cnv2icudf (line 131) Unrecognized minute format.
Format string: DD/MM/YYYY HH:MM:SS.
Error in datevec (line 112) icu_dtformat = cnv2icudf(varargin{isdateformat});`
Assuming your data is in a matrix or cell-array of strings called A, and your other data is in a vector X. Let's say all the data is in the same year (so we can ignore years)
[~,M,D,H] = datevec(A, 'dd/mm/yyyy HH:MM:SS');
mean_A = accumarray([M, D, H+1], X, [], #mean);
Then data from February will be in
mean_A(2,:,:)
To look at the data, you may find the squeeze() function useful, e.g.
squeeze(mean_A(2,1:10,13:24))
shows the average for the hours after midday (by column) for the first ten days (by row) of February.
See also:
Counting values by day/hour with timeseries in MATLAB
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
i would like to simulate random timestamp data.
100 records in a day for one year.
How am I am able to do that?
when i set a:2013.01.01D00:00:00.000000000
100?a
the randomize data doesn't stay in a day.
thanks for your input
I am not sure, if this can be done easily. But you may generate 100 random timestamps for every day of 2013 in the next way
daysInYear: 365;
year: 2013.01.01D00:00:00.000000000;
//array of 365 elements, where every element represents corresponding date of year
dates: year + 01D * til daysInYear;
//array of 365 elements, where every element is an array of 100 random timestamps [0 .. 1D)
randomNanos: cut[100; (100 * daysInYear)?1D];
//array of 365 elements, where each element is an array of 100 random dateTimes for given day
result: dates + randomNanos;
//put all the dates in single array
raze result
The short version which does the same is below:
raze (2013.01.01D+01D * til 365) + cut[100; (100*365)?1D]
In order to simulate data for a single day, it's possible to generate random times (as floats less than one) and add them to the day you would like to generate data for. In this case:
D:2016.03.01;
D+100?1f
Will return 100 random times on 2016.03.01. If you want to generate data within a time range you can restrict the size of the float to something less than 1, or greater than a certain minimum value.
If you want to handle leap years... Not sure of a better way at the minute other than adding the max number of days onto the start of the year and asking whether it's the 31st. Adding on 366, it can either be 31st or 1st. If it's the 31st good, otherwise drop off the last date.
/e.g.
q)last 2015.01.01+til 365
2015.12.31
q)last 2016.01.01+til 365
2016.12.30 /we are a day short
q)
/return the dates and the number of days based on whether its a leap year
q)dd:$[31i~`dd$last d:2016.01.01+til 366;(366;d);(365;-1_d)]
q)/returns (366;2016.01.01 2016.01.02...)
q)/the actual logic below is pretty much the same as the other answer
q)raze{[n;dy;dt] dt+n cut(n*dy)?.z.N}[100;].dd
2016.01.01D16:06:53.957527121 2016.01.01D10:55:10.892935198 2016.01.01D15:36:..
i have a column which has data in "12:19:04" this format.
i.e 12 hours 19 min and 4 sec.
i want to convert this into number of days considering working hours as one day i.e 10 hr
so the above time should be displayed as 1 day 2 hr 19 min and 4 sec
and also if the hours value is too huge then month days hours and minutes should be displayed.
Kindly help me in this.
Easiest way: Use epoch time, divide by 10 days in seconds, convert remainder back to seconds.
WITH s(secs) AS (SELECT extract(epoch from interval '12:19:04'))
SELECT justify_interval(
floor(secs / 36000) * INTERVAL '1' DAY
+ (secs::integer % 36000) * INTERVAL '1' SECOND
) FROM s;
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