I am using Hyperion Reporting Studio with Oracle and DB2 databases. We have fields that have an open date and a close date on them, so naturally the format would be 6/02/16 06:18:05 PM for either the open or close date fields. Is there a way to trim off the date section to be left with only the time stamp? I have tried TURNC as well as custom SQL and nothing is working. I know I can do it in excel using the =TIME formula. I could either add the computed item in the query or the results, im just not sure what to do.
2 Answers
Perhaps proper use of to_char?
SQL> select to_char(sysdate,'dd-Mon-yyyy hh24:mi:ss') full_date,
2 to_char(sysdate,'yyyy-mm-dd') date_only,
3 to_char(sysdate,'hh24:mi:ss') time_only
4 from dual;
FULL_DATE DATE_ONLY TIME_ONL
-------------------- ---------- --------
03-Jun-2016 16:30:38 2016-06-03 16:30:38
For a more complete explanation of date/time formats in Oracle, see http://edstevensdba.com/oracle-data-types/understanding-oracle-date-formats/
One way is to change the datatype. This is not the proper way to do it, and might be ill-advised depending on what you're doing, but it will save a lot of headaches with formatting.
To change the datatype: in the Query section, in the field on the request line, go to the Properties (can double-click, or right-click and select Properties). This will show you the SQL for that column/field. On the right, there will be a button Options. All it does is reveal the datatype. This is usually Hyperion's best guess based on the underlying data source. Change it to Time and process it again. This will change all the subsequent uses of that field for every child section: the Results, Pivots, and so forth based on that query section.
Another way is to change the number format. This is what to use if you just care about the cosmetic, and only want it to apply to that section. In the section (Results/Pivot/etc), right-click the column, and select Number. Then, select the time format that suits you.
Another way, if you really need to strip the date off for calculations, you could convert it to a string, remove the date from the string, and then convert it back to a time. In the Results section, right-click, Add Computed Item, then do something like
var objField = YOUR_DATETIME_COLUMN;
var strField = ToChar(objField);
var numFirstspace = strField.indexOf(' ');
var strTime = strField.substring(numFirstspace);
var tmTime = ToDate(strTime);
tmTime
Assuming I got that correct, it will still show something like 01/01/1904 HH:mm AM/PM
... so you still have to right-click the column, select Number, and change the number format to your time.
Another way, is to add a computed item in your query's request line. This entails doing the same as the last version, but using SQL syntax instead of Hyperion's version of Javascript.