Using TimeStampDiff
Have a customer who want to see the total time spent in a location by location - I have the enter time and the exit time (both timestamps) and am able to calculate the difference using TimeStampDiff, however I want to create an aggergration on the total time by location? I can get the individual transaction time difference but can not figure out how to aggergrate these individual transactions together to get a "sum of time" by location?
Any suggestion?
Hi,
Try this............
sum(TIMESTAMPDIFF(interval, tablename.entry_time, tablename.exit_time) by tablename.location)
The specified interval. Valid values are: SQL_TSI_SECOND, SQL_TSI_MINUTE, SQL_TSI_HOUR, SQL_TSI_DAY, SQL_TSI_WEEK, SQL_TSI_MONTH, SQL_TSI_QUARTER, SQL_TSI_YEAR
Cheers,
Aravind
Similar Messages
-
Subtracting Datetime using timestampadd or timestampdiff in Obiee
Hi,
I am trying to subtract the current date to the date i need without using between in the filters but using TIMESTAMPADD OR TIMESTAMPDIFF
For ex
From: 12/01/2013
TO: 12/07/2013
so i want only those records to be shown (between those records as well as the start date and end date)
Thank you,So what's your problem using TIMESTAMPDIFF?
TIMESTAMPDIFF(SQL_TSI_DAY, Time."Day Date", CURRENT_DATE) -
Hello experts,
I want to know How to use TimeStampDiff function appropriately.
My requirement is I have a column in the physical layer say time. It is of datatype varchar(5). It stores the values in HH:MM format.
I want to have the difference between the current time and this column.
For current time, Im using function in OBI Answers: CURRENT_TIME(2) where 2 denotes the precision of seconds.
The formula Im using is TIMESTAMPDIFF(SQL_TSI_MINUTE, CAST("Query Time".Time AS TIMESTAMP), CURRENT_TIME(2)).
This is throwing the following error:
ORA-01843: not a valid month at OCI call OCIStmtExecute: select D1.c1 as c1, D1.c2 as c2, D1.c3 as c3, D1.c4 as c4, D1.c5 as c5, max(D1.c6) over () as c6 from (select distinct D1.c2 as c1, D1.c3 as c2, D1.c4 as c3, TO_DATE('1900-01-01 03:54:07' , 'YYYY-MM-DD HH24:MI:SS') as c4, D1.c1 as c5, D1.c1 as c6 from (select max(T45654.TOTAL_TIME_SEC) as c1, TRUNC(T45677.DAY_DT) as c2, ROUND( ( TO_DATE('1900-01-01 03:54:07' , 'YYYY-MM-DD HH24:MI:SS') - CAST( cast(T45654.START_HOUR_MIN as DATE) as DATE) ) * 1440 ) as c3, T45654.START_HOUR_MIN as c4 from S_ETL_DAY T45677, S_NQ_ACCT T45654 where ( T45654.START_DT = T45677.DAY_DT and T45654.SAW_SRC_PATH = '/shared/PI BOOK of Business - P2/AE Home Page/Search/P2 - Trust Request' and TRUNC(T45654.START_DT) = TO_DATE('2009-03-09' , 'YYYY-MM-DD') and TRUNC(T45677.DAY_DT) = TO_DATE('2009-03-09' , 'YYYY-MM-DD') ) group by T45654.START_HOUR_MIN, TRUNC(T45677.DAY_DT) ) D1 ) D1 order by c1 desc, c2, c3, c4. [nQSError: 17011] SQL statement execution failed. (HY000).
Can anybody help me get the right formula?
thx,
paragHi.
I try the similar:
TIMESTAMPDIFF(SQL_TSI_MINUTE, CAST('14:22' AS TIMESTAMP), CURRENT_TIME(2))
and I got an error:
State: HY000. Code: 10058. [NQODBC] [SQL_STATE: HY000] [nQSError: 10058] A general error has occurred. [nQSError: 17001] Oracle Error code: 1843, message: ORA-01843: not a valid month at OCI call OCIStmtExecute: select distinct D1.c1 as c1, ROUND( ( TO_DATE('1900-01-01 12:05:33' , 'YYYY-MM-DD HH24:MI:SS') - CAST( cast('14:23' as DATE) as DATE) ) * 1440 ) as c2 from (select distinct T21473.PROD_CATEGORY as c1 from PRODUCTS T21473 ) D1 order by c1, c2. [nQSError: 17011] SQL statement execution failed. (HY000)
So the syntax is:
TimestampDiff (interval, timestamp-expression1, timestamp-expression2)
If you harcode it:
Timestampdiff(SQL_TSI_MINUTE, TIMESTAMP '2009-04-28 12:00:00', current_timestamp)
The results is difference in minutes.
So you just need to put 'the right expression' in the second place. Try to concatenate current date with your time value and place it insted of TIMESTAMP '2009-04-28 12:00:00' because this inputs only timestamp format.
Hope this helps.
Regards,
Goran
http://108obiee.blogspot.com/ -
TimeStampDiff function ROUNDing the result. How can we avoid this?
Hi,
I am using the following timestamp function:
TIMESTAMPDIFF(SQL_TSI_HOUR, "SF_CS_CS_Fact"."Crtddt_Dt", "SF_Emlmssg_Sum_CS"."Initl Resp Tm")
I notice that the result set is rounded off to the whole no.
This is happening because OBIEE autimatically ROUNDS the difference of the timestamps whe using TIMESTAMPDIFF:
select distinct D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9,
D1.c10 as c10
from
(select D1.c1 as c1,
D1.c2 as c2,
D1.c3 as c3,
D1.c4 as c4,
D1.c5 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9,
D1.c10 as c10
from
(select 0 as c1,
D1.c4 as c2,
D1.c5 as c3,
D1.c3 as c4,
D1.c2 as c5,
D1.c6 as c6,
D1.c7 as c7,
D1.c8 as c8,
D1.c9 as c9,
D1.c1 as c10,
ROW_NUMBER() OVER (PARTITION BY D1.c2, D1.c3, D1.c4, D1.c5, D1.c6, D1.c7, D1.c8, D1.c9 ORDER BY D1.c2 ASC, D1.c3 ASC, D1.c4 ASC, D1.c5 ASC, D1.c6 ASC, D1.c7 ASC, D1.c8 ASC, D1.c9 ASC) as c11
from
(select distinct ROUND ( ( CAST(T14421.INITIAL_RESPONSE_TIME as DATE) - CAST(T14963.CRTDDT_DT as DATE) ) 24 ) as c1*,
T14963.CRTDDT_DT as c2,
T14963.CSNMBR as c3,
T4813.FISCAL_YEAR_NAME as c4,
T4813.FISCAL_QUARTER_NAME as c5,
T14421.INITIAL_RESPONSE_TIME as c6,
T14468.GRP as c7,
T4813.FISCAL_YEAR_ID as c8,
T4813.FISCAL_QUARTER_ID as c9
from
DW_SF_EMLMSSG_SUM_CS T14421,
DW_SF_EMLMSSG_CS T14400,
SF_ORGN_CS_DIM T14468,
CIN_CALENDARS_DIM T4813,
DW_SF_CS_CS T14963 /* SF_CS_CS_Fact */
where ( T14400.PRNTID = T14963.ID and T4813.CALENDAR_KEY = T14963.CRDT_KEY and T14421.PRNTID = T14963.ID and T14400.STTS = '3' and T14468.ORGN_KEY = T14963.ORGN_KEY and T14963.TYP = 'CIN' and (T14963.CSNMBR in ('1103676964', '1103677035', '1103677076', '1103677285', '1103677303', '1103677369', '1103677389')) )
) D1
) D1
where ( D1.c11 = 1 )
) D1
order by c1, c8, c9, c7, c4, c5, c6, c10
Please see the line in Bold in the query.
I want to get the results in the actual decimal point and not the whole no. Is there a way that I can enable the TIMESTAMPDIFF not to ROUND by default.
Any answers will be helpful.
Thanks,When you specify in the interval in the first argument of TIMESTAMPDIFF you are implicitly telling OBIEE the level of precision that you want. For SQL_TSI_YEAR you are going to get integer values of whole years. if yo uneed to get more granular than that you need to use SQL_TSI_MONTH or WEEK.
Also note, than when performing mathematical operations like divide an multiply, all elements of the calculation need to be a data type that can represent decimal values, or the result of the entire calc will always get converted to an integer. -
TIMESTAMPDIFF function in combined analysis
Hello,
Has anyone used the timestampdiff function in a combined analysis? I have created a combined analysis with using two subject areas and tried using the timestampdiff function in the results section but its not giving me the right results. I am using timestampdiff(sql_tsi_day, saw_5, saw_3).
Any help is appreciated.
Thanks!
SoniaI guess you can use TIMESTAMP functions in result columns. The only case where you may hit an error is when one of the columns(say saw_5) is having a null/blank value for the corresponding value in saw_3.
-
TIMESTAMPDIFF rounding to 2 decimal places instead of 0
Hi,
Requirement is to find difference between two timestamp column,
as known one we cannot perform arithmetic operation in non number type in rpd.
Hence tried using TIMESTAMPDIFF function as below,
TimeStampDiff(SQL_TSI_MINUTE, MONITOR_TIMESTAMP, ATT_TIMESTAMP" )
OBIEE server converting this function to below SQL ,
ROUND( ( CAST(ATT_TIMESTAMP as DATE) - CAST(MONITOR_TIMESTAMP as DATE) ) * 1440 )
this returns value as ex: 12 as rounded value without any decimal places.
but we want to have two decimal places, how to fix this or any work around ?
Thanks,
Satheeshinstead of * 1440
do with
* 1440.00
btw: why you need to cast to date? why cant be timestamp?
Discard it -
Is there a way to calculate age from DOB in the RPD business model layer? In the table, there is only DOB stored in string format (e.g. 19700125, YYYYMMDD format) and we need to dervie age in the RPD.
Here's a hint:
use TimestampDiff funtction
such as TimestampDiff (SQL_TSI_YEAR, date1, now() )
You might have to use CAST function to turn your column into date type....
I hope this is helpful. -
hai bloggers,
see we have 365 days per year for first half we are going to have 180+ days (if we select first half as the prompt and we select week number as prompt and the last date of that particular week should show in the report)and number of days upto that date or week also should display...if we select second half and week number of that particular half it should show number of days upto that week and highest date of that week number of days should count from 1 to 180+ only mean (july 1 st is 1 st day)
thanksYou need to use timestampdiff function for calculating number of days. One of the way to calculate is like this
case when "Time"."Calendar Half Year" = 1 then timestampdiff(SQL_TSI_DAY,CAST(EVALUATE('TO_DATE(%1,%2)','01-01'||'@{YEAR}{2010}','DD-MM-YYYY') AS DATE),CAST(EVALUATE('TO_DATE(%1,%2)','30-06'||'@{YEAR}{2010}','DD-MM-YYYY') AS DATE)) else timestampdiff(SQL_TSI_DAY,CAST(EVALUATE('TO_DATE(%1,%2)','01-07'||'@{YEAR}{2010}','DD-MM-YYYY') AS DATE),CAST(EVALUATE('TO_DATE(%1,%2)','31-12'||'@{YEAR}{2010}','DD-MM-YYYY') AS DATE)) end
If you want calculate between 1st day of the half and last date of a week then use following
case when "Time"."Calendar Half Year" = 1 then timestampdiff(SQL_TSI_DAY,CAST(EVALUATE('TO_DATE(%1,%2)','01-01'||'@{YEAR}{2010}','DD-MM-YYYY') AS DATE),MAX(MAX("Time"."Calendar Date"))) else timestampdiff(SQL_TSI_DAY,CAST(EVALUATE('TO_DATE(%1,%2)','01-07'||'@{YEAR}{2010}','DD-MM-YYYY') AS DATE),MAX(MAX("Time"."Calendar Date"))) end
Hope it will answer your question
Thanks,
Phani. -
How to add a column that shows the difference of two metrics columns?
I created a pivot table with two metrics columns. One metrics column has the aggregation rule of 'Min', the other has 'Max'. Now I want to add a column to show the difference of these two metrics for each row. Is this possible? How to do it? Thank you in advance.
Use TimeStampdiff:
TIMESTAMPDIFF(SQL_TSI_HOUR, MIN(xxxx), MAX(xxx))
It's in the help file if you need more help.
regards
Alex -
Hi,
I would like to compare two dates on a report.
I would like to compare the opportunity created date and the opportunity modified date. I can't use this formula CASE WHEN Opportunity."Last Modified" = Opportunity."Created Date" then 1 else 0
I think I have to use TIMESTAMPDIFF but I don't know which interval I have to put to analyze the entire date in this format 31/12/1999 16:49:08
Thanks a lot for your help
Regards,Hi !
It depends on the interval you need to compare these dates. If you want to know the number of days between these dates, you'll have to use SQL_TSI_DAY as interval. If it's minutes, you'll need SQL_TSI_MINUTE...
Here are the possible intervals :
*SQL_TSI_SECOND, SQL_TSI_MINUTE, SQL_TSI_HOUR, SQL_TSI_DAY, SQL_TSI_WEEK, SQL_TSI_MONTH, SQL_TSI_QUARTER, or
SQL_TSI_YEAR*
Hope this will help, feel free to ask more !
Max -
Hi,
In Obiee, I am having customer DOB but i want customer Age as column in BMM layer. How can i get that?This seems to handle all the scenarios,
CASE
WHEN
EXTRACT( MONTH FROM BIRTH_DATE) > EXTRACT( MONTH FROM NOW())
THEN
TIMESTAMPDIFF( SQL_TSI_YEAR , BIRTH_DATE, CURRENT_DATE ) - 1
WHEN
EXTRACT( MONTH FROM BIRTH_DATE) = EXTRACT( MONTH FROM NOW())
AND EXTRACT( DAY FROM BIRTH_DATE) > EXTRACT( DAY FROM NOW())
THEN TIMESTAMPDIFF( SQL_TSI_YEAR , BIRTH_DATE, CURRENT_DATE ) - 1
ELSE TIMESTAMPDIFF( SQL_TSI_YEAR , BIRTH_DATE, CURRENT_DATE )
END
For details, http://www.sagelogix.com/sagelogix/knowledge/techtips/SAGEWEB000588
Also worth reading below postto understand the need for the case statements above,
Problems calculating age using TimeStampDiff
Edited by: 855532 on May 25, 2011 2:24 AM -
Hi gurus,
In the rpd, I have a condition where
If (received_date- current_date) < X then ....
the received date in the database is numeric. Ex : 20040810
How do I change the date format to match the default current date in the expression builder.
Thanks
AvinashLooks like you are using this calculations based on fact table or might be physical columns.
I would suggest to use logical columns so that you can use the date(for received_date) column your day dim.
or else
map the day dim to fact table and use physical expression for the same, its same as your other post with status=completed as I said in my last email.
You have to use timestampdiff function.
If helps mark
Edited by: Srini VEERAVALLI on Feb 20, 2013 2:47 PM -
How to calculate two date diff?
what is the similar function in BIEE? like datediff = date1 - date2 SQL statment in Oracle db,
i have tried to use minus, it was not works, BIEE does not support minus two date directly?
thanks a lot!
Kaymoyou can use timestampdiff function. The TimestampDiff function returns the total number of specified intervals between two timestamps.
Syntax:
TimestampDiff (interval, timestamp-expression1, timestamp-expression2)
example TimestampDiff (SQL_TSI_DAY, date1, date2) returns the number of days between date1 and date2.
The specified interval. Valid values are:
SQL_TSI_SECOND
SQL_TSI_MINUTE
SQL_TSI_HOUR
SQL_TSI_DAY
SQL_TSI_WEEK
SQL_TSI_MONTH
SQL_TSI_QUARTER
SQL_TSI_YEAR -
Hello.
I want to convert date field to number. I used TIMESTAMPDIFF(SQL_TSI_DAY, "Invoice date (invoice header)".Date, CURRENT_DATE ) to get number of days from invoice date to current day but this number is treated as date format and I'm not able to make calculation on that number. Any suggestions how to convert this »number« to real number that also calculation would be possible.
Thank you.
Brgds, LukaAny hint or is not possible as Kishore said....
I would like to sum (grand total) all the days that I get from TIMESTAMPDIFF.
Example:
Invoice nr. Due date TIMESTAMPDIFF(SQL_TSI_DAY, "Invoice due.date (invoice header)".Date, CURRENT_DATE )
201001006978 30.11.2010 44
201001007250 8.12.2010 36
201001007392 15.12.2010 29
201001007735 23.12.2010 21
201001007815 30.12.2010 14
SUM = 144
Brgds,
L -
hi all
how to find the timestampdiff function
can any one give me the syntax
Thanks
Sreedharhi Sreedhar,
Try in google before posting in forums
My Google results for you
You can use TimestampDiff to get the date difference.
Here is the syntax:
TimestampDiff(interval, timestamp1, timestamp2)
Where:
-- > interval = The specified interval.
Valid values are:
SQL_TSI_SECOND,
SQL_TSI_MINUTE,
SQL_TSI_HOUR,
SQL_TSI_DAY,
SQL_TSI_WEEK,
SQL_TSI_MONTH,
SQL_TSI_QUARTER,
SQL_TSI_YEAR.
thanks,
Saichand.v
Maybe you are looking for
-
How to convert mobi books to ePub format?
Hello, I have a question for help here, I have a lot of .mobi books on my computer, I wanna transfer these mobi books to my iPhone and iPad for reading, but I found they doesn't accept mobi format, I tried many ways to convert mobi to ePub but failed
-
How do I get past the empty blue screen?
I keep getting the empty blue screen. I have tried starting up in Safe Mode only to wind up with the same blue screen. Tried starting up with iMac install disc only to wind up with the same blue screen. Additionally it has decided to keep the disc. T
-
Problems in deleting relationship in PO13
Hi, I am facing a problem when performing following steps. Please give you valuable comments regarding any solution. Step1: sm30 Payroll Period & Year - Verified values Step2: PO13 Clear position for Transfer , go to maintain position In this step un
-
FCH1 - Check List No data found
Dear SAP Experts, We are in the middle of technical upgrade to ECC6. I tested the "FCH1 - Display Check Information" in ECC6, from the menu bar I select "Check - List" to display the list of checks. The system displays no data found. However in 4.7
-
Premier Pro 1.5 on Windows XP service Pack 3 Tried opening adobe and got message that there was a CHANGE IN THE configuration and I have to activate my product. Clicked OK but the system hangs up. Tried the tech pages. Downlead the almud patch but