Convert hours:minutes to seconds where hours > 24 - amazon-redshift

I have a string 47:45.
That means 47 hours, 45 minutes.
I want to convert that string to seconds.
select datediff(second, '00:00','47:45') <-- does not work
what is the quickest way to find the 171.900 seconds I am looking for?

One way to do this would by delimiting the semicolon separated values and multiplying the minutes part by 60 and hours by 3600 and adding the result.
Thanks!

Related

Hour conversion in Tableau

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

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

MATLAB- Adding Terms In An Array

I am fairly new to programming, and I am have a difficult time with finishing a function to use in my homework assignment. Below I have the code for a function that is intended to take the month entered subtract 1 from it, and add the number of days that are entered. Returning the total number of day. For example, if m=4, days= 3, then it would go through the for loop and add 31+28+31+4. I would greatly appreciate your help. Thank you for your time!
function bday=daysinmonth(m, d)
array=[31 28 31 30 31 30 31 31 30 31 30 31];
for i=1:m-1
md=sum(array(i))
end
%sum=md+d
end
The array holding the number of days for each months is a good starting point. Then I don't understand why you iterate up to the month. What you are looking for is the sum up to the current month, so something like:
md=sum(array(1:m-1));
And yes, then you can add the current day to the accumulated days from previous months with
sum=md+d;
You also want to make sure, that you return the this number with
function sum=daysinmonth(m, d)

Create intervals with 'datenum'

I am creating the limits for an equally spaced time series and I need to be able to change the time interval (1min, 5min, 10min, 15min, 30min, 60min etc.). My bounds are opening and closing time of the market. The stocks I am working on trades from 17.00 to 16.15 of the day after.
Here is what I am using:
timevec=datenum(2013,1,1,17,0:1*interval:1395,0)';
% It creates a time vector from 1-1-2013 17.00.00 to 1-2-2013 16.15.00
% spaced by "1min*interval"
The formula to be used is pretty simple but a problem arise if I need to use 10min or 30min as the result would be:
(10min)
02-Jan-2013 15:50:00
02-Jan-2013 16:00:00
02-Jan-2013 16:10:00
(30min)
02-Jan-2013 15:30:00
02-Jan-2013 16:00:00
What I would like to have is an extra interval 16:20:00 for the ten min case and 16:30:00 for the 30min case. The only solution I can come up with is moving the bound to 16:30 and adding an if statement to remove the extra observations in case they are not needed or keep the bound at 16:15:00 and adding an if statement to add the extra observation in case they are needed.
Is there anyway to do a one-line able to treat these two cases?
Matlab creates ranges such that all values are inside the limits. If you want to add one additional value right outside the limits, you can modify the upper limit by adding almost one interval length to the end:
step = 15;
1:step:100+0.99*step
ans =
1 16 31 46 61 76 91 106

How to convert Number of hours into number of work-hours days in postgreSql?

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;