Need help converting Integer to Time - sql

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?

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

SSRS/SQL How to plot HH:mm:ss on graph?

Hi all this is my first time posting on Stack Overflow.
I'm trying to plot a chart that displays names of some schedules we run, and their total run time duration. What I'm trying to achieve is to show our 5 slowest schedules. SQL data output is something like this:
SQL Output
Note for elapsed above, this is currently cast as TIME, however I have also had it in the format of 03:19:02 without the milliseconds afterwards as well by using CONVERT VARCHAR 108.
My graph
In the screenshot above you can see the schedule numbers on the left and the elapsed time on the bottom.
Things I have tried so far:
Setting the format under number to HH:mm or HH:mm:ss. Neither of these work, when I do this it results in this:
My attempt at custom Number formats
How it looks after I save the number format
As you can see it just plots a ridiculous HH:mm continuously on the bottom axis as opposed to an actual time. This happens whether my data is plotted as convert varchar 108 or CAST as TIME.
I've also attempted to go under Axis Options and changed Interval type to Hours or days or minutes etc, if I try any of those the axis just disappears as below:
Interval Type Changed to Hours
Interval Type Changed to Hours output with disappearing axis
Let me know what I'm doing wrong in the above team! Thank you!
It looks like you are not showing the actual duration but a count (which is always 1).
Look under Chart Data / Values and make sure your aggregate is e.g. a MAX and not a COUNT.

Time Formatting for MS Access Query

I'm trying to figure out the proper syntax to converting a total of minutes to show properly. For example: if something shows 65 minutes I want it to show 1:05.
What I have been messing with is as follows:
Format(Round(DateDiff("n",[StartDate],[DateCompleted]),2),"Short Time")
The query has totals turned on as this field is set to Expression. I'm getting strange results with the current criteria.
I'm sure there is something simple I'm missing but I haven't been having much luck.
Thanks!!!
As long as you won't exceed 24 hours, you can do it straight:
Duration: Format([DateCompleted]-[StartDate],"Short Time")

autofill leading zero depending on length in sql (odbc on db2 w/ squirrel)

I have a database table where the timestamps are like following:
TIME
85000
91000
171500
171500
how can I transform that into something like
0850
1715
...?
The defined length of this value is always 6, so I need to work with trim (I guess) in order to first identify if the time was before 10:00 or vice versa.
Cutting the value with left or right won't help right away, also, I do not have all sql-commands due to odbc to DB2 on as400.. so that is a bummer as well.
Here is another way that works:
left(digits(timestamp),4)
Note that timestamp is not really a timestamp, but a decimal(6,0) value. This will also work for times like 0015 or 0001 where you would need to concat('000000', timestamp) for your solution to work in the first hour after midnight.
I have managed now, seems to work as wanted:
left(right(concat('0',timestamp),6),4) as formatted_time
I first added a zero at the beginning:
concat('0',timestamp)**
in order to have a length of 6 also for the timestamps smaller than 10:00.
Then I grabbed all six characters from the right
right(concat('0',timestamp),6)
and finally the first 4 characters of this new result
left(right(concat('0',timestamp),6),4)
and got
0600
0945
1315
I am aware that this is not the most elegant or efficient solution. Of course I do appreciate further input.

Total Hours Format in Moment.js

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