Total Hours Format in Moment.js - datatables

I'm creating a data table using DataTables.net where a column contains the cumulative running hours of an event. I'm simply adding to the hours each time, so I have for example:
40:34:30
which is 40 hours, 34 minutes, 30 seconds.
My problem is I want to order this column by hours, and I haven't been able to find anything that supports this from Moment.js. Ideally I imagine it would be something like "HHH:mm:ss", or something like that. As it stands, the column recognises the fields as strings, so 0:12:34 is appearing above anything else in descending order despite only being 12 minutes long.

You can sort HH:mm:ss by re-formating it to seconds before sorting.
moment.duration('40:34:30').asSeconds;
gives you 146070. Then simply use seconds in your sorting script.
here is the solution: jsFiddle
And if you really need just the hour part; use Math.floor: jsFiddle

Related

Invalid Time String Error when trying to change type of data from string to time

I am very new to data analytics and I need some help troubleshooting a SQL error I got. So, I have a column in this table which transferred over from Excel to SQL as a string type rather than a time piece of data. I want to make it into a time type so i can further analyze it.
So, I did the attached query to try and change the type of data using the CAST function. . However, it could not complete the query thanks to an outlier in the data set I have yet to clean the data and this was one of my first steps to so, but how do I remove this particular row that contains the invalid time string so the query can actually work? Or is there a better way to convert this entire column from text string to time?
BigQuery Time types adjust values outside the 24 hour boundary - 00:00:00 to 24:00:00; for example, if you subtract an hour from 00:30:00, the returned value is 23:30:00.
Based on your screenshot it looks like you are storing a duration? So 330 hours, 25 minutes and 55 seconds?
You would probably be best using timestamp, converting the hours to days and adding the remainder to your minutes and seconds.
You can then cast the resulting string to timestamp.
Edit
A much simpler solution is just cast('330:25:55' as interval) - thanks to #MatBailie

Need help converting Integer to Time

I looked through online solutions for this, none worked for me so I'm posting here. I have separate date and time columns, both stored as integers. I am able to convert the date column to DATE, but not for the Time column. The column value is: 52700, when using TO_TIME(TO_CHAR(OHCRTM)) I get 14:38:20 but it should be 07:27:00. I've tried various formatting (TO_TIME(TO_CHAR(OHCRTM),'HH24.MI.SS') but I get a 'cannot parse' error. Any idea how I can get the correct time?
14:38:20 is the right answer, unless you can give us the logic that would make it 07:27:00.
52700 seconds are exactly 14 hours, 38 minutes, and 20 seconds.
Another option to read 52700 would be a time without the colons, ie 05:27:00. To parse it like that the needed SQL is:
select to_time(52700::string, 'HHMISS');
I guess 05 becomes 07 after a timezone conversion then?

Time Addition in Sql Server

I have two time value like
Time1=23:59:59:999
Time2=23:59:59:999
when i add up these two time (Time1+Time2) and i want result will be 47:59:58 rather than 23:59:58.
How can i do this? please suggest!!
Let's look at times and durations:
A datetime is a moment in time, say June 28, 1978 at 15:23.
A time without a datepart is a repetitive moment in time, e.g. "I get up every day at 7:00". (This is what you are using. But I get up at 8:00 and go to sleep at 23:00 doesn't make 8 + 23 = 31. It makes no sense to add times.)
Then there is timespan (e.g. from 2016-01-01 3:00 to 2016-01-02 13:00).
And then there is duration (e.g. six minutes). This is what you want to deal with.
You are storing a duration in a time, which is not really the appropriate data type. As SQL Server does not provide a special data type for a duration, you can use a numeric type for this and store seconds or microseconds or whatever you think appropriate. These you can easily add (provided both values have the same unit, e.g. microseconds).
As to displaying the duration you can write a function providing you with the format you like best for a duration (e.g. '913 days, 9 hours, 5 minutes, and 55.123 seconds').
Actually, that is really hard in SQL Server. How about '1 23:59:58'? If so:
select cast(time1 as datetime) + time2
If you actually want the format in HH:MM:SS format, then you will need to do a lot of string manipulation.

weird intervals in postgresql

I am working with postgresql and when i want to calcalute the average of some intervals between
two timestamps. The intervals are correct but I get something like "235 days 29:28:02.642857"
I find it strange that it says 235 days and 29 hours instead of 236 days and 5 hours.
As noted by #pozs, you can use justify_hours(interval) to get them converted properly. If you want to convert the days to months, you may use justify_days(interval). If you want to do both at once, do justify_interval(interval)

Google Bigquery table decorators

I need to add decorators that will represent from 6 days ago till now.
how should I do it?
lets say the date is realative 604800000 millis from now and it's absolute is 1427061600000
#-604800000
#1427061600000
#now in millis - 1427061600000
#1427061600000 - now in millis
Is there a difference by using relative or absolute times?
Thanks
#-518400000--1
Will give you data for the last 6 days (or last 144 hours).
I think all you need is to read this.
Basically, you have the choice of #time, which is time since Epoch (your #1427061600000). You can also express it as a negative number, which the system will interpret as NOW - time (your #-604800000). These both work, but they don't give the result you want. Instead of returning all that was added in that time range, it will return a snapshot of your table from 6 days ago....
Although you COULD use that snapshot, eliminate all duplicates between that snapshot and your current table, and then take THOSE results as what was added during your 6 days, you're better off with :
Using time ranges directly, which you cover with your 3rd and 4th lines. I don't know if the order makes a difference, but I've always used #time1-time2 with time1<time2 (in your case, #1427061600000 - now in millis).