Calculating Date Difference
Hello,
I am trying to calculate the difference between dates. I have a date_received column and a date_compleated column in my table with data type "date". The values are strings originally, and are converted and stored in the database using to_date. For instance: to_date(:DATE_REC,'DD-Mon-YY HH:MI:SS AM'). When I query the database, I get a negative number for difference.
Query
SELECT to_char(date_compleated, 'DD-MON-YY HH:MI:SS AM') date_comp,
to_char(date_received, 'DD-MON-YY HH:MI:SS AM') date_rec,(date_compleated - date_received) Diff
FROM cs_request
where job_number = '23089791';
Results
DATE_COMPL
10-JUL-08 03:09:43 PM
DATE_REC
09-JUL-08 08:09:08 AM
DIFF
-730485.70792824074074074074074074074074
Why am I getting a negative number? Any suggestions would be greatly appreciated.
Sharon
Quite possibly that DATE_COMPLEATED value got converted to :
'10-JUL-0008 03:09:43 PM'
instead of:
'10-JUL-2008 03:09:43 PM'
test@ora>
test@ora>
test@ora> --
test@ora> with t as (
2 select to_date('10-JUL-0008 03:09:43 PM','DD-MON-YYYY HH:MI:SS AM') as date_compleated,
3 to_date('09-JUL-2008 08:09:08 PM','DD-MON-YYYY HH:MI:SS AM') as date_received
4 from dual)
5 --
6 SELECT
7 to_char(date_compleated, 'DD-MON-YY HH:MI:SS AM') date_comp,
8 to_char(date_received, 'DD-MON-YY HH:MI:SS AM') date_rec,
9 (date_compleated - date_received) Diff
10 FROM t;
DATE_COMP DATE_REC DIFF
10-JUL-08 03:09:43 PM 09-JUL-08 08:09:08 PM -730486.21
1 row selected.
test@ora>
test@ora>
test@ora>
test@ora>What is the output of this query ?
SELECT to_char(date_compleated, 'DD-MON-YYYY HH:MI:SS AM') date_comp
FROM cs_request
where job_number = '23089791'; HTH
isotope
Similar Messages
-
Date Difference Calculation in BW3.5
Hi
We are calculating date differences between 2 dates i.e. Delivery Date - System Date.For System date we used variable exit to derive the value.But when we create CKF on Delivery Date,we necessary have to keep date field in Drilldown(in rows).But reports needs to give Overview while including date field in rows removes the granularity.
Is thier any other way we can handle this situation.
Regards
PraveenYou have to put ur delivery date in Rows if u r doing the Formula variable with replacement path. There is no option.
Khaja -
Calculation of difference of wages types master data and accounting cluster
Hi, I am developing a ABAP HR report for calculating the difference of wage types master data and accounting data and in the output i need to display the fields like
Officer in-charge of payroll accounting
Officer in-charge of Support
Officer in-charge of time recording
also from where I could get the accounting cluster data for the wage types
I want to know from where I can get these fields and how ther are related with wage types.Check through PA30,there are different infotypes by which these data are maintained in the Employee Master.
-
Xcelsius doesn't display the date difference in Preview
Hi,
Im using the Xcelsius Enterprise 2008 and I use XML connectivity for the source. I would like to do some date difference calculation on my spread sheet. But the result of the date difference does no appear on the Preview for some reason. My XML file has got the date format dd/mm/yyyy hh:mm. I tried to convert the date to number format by multiplying the date by 1. When I do this the result appears correctly as I want on the Preview, but the problem is when there is a first refresh, the date difference shows a error value "#Value". I tried to enable XML Map Properties -> When refreshing or importing data:
1. Overwrite existing data with new data
2. Append new data to existing XML lists.
But still not of any use. Could any one please give me a tip to resolve my problem.
Many thanks in advance.
PriyaHi Priya
Can you please tell me what formula are you using to take difference in dates?
Just to tell you as a point of information, Xcelsius is capable to handle very limited set of formulas. In spreadsheet you will see the formula working perfectly fine but right after hitting preview button you wont be able to see values calculated by certain formulas in Excel. So, its always good to use less and very basic formulas.
Regards,
Waqas -
Hello Guys, how are you.
I'm facing a problem whan I try to get the difference between the max and min date of a KF.
Mi requirement is like this:
Min Date Max Date Difference (max - min)
20/06/2008 26/06/2008 6
My query result is like this:
min date max date difference
20/06/2008 26/06/2008 0
It seems like the formula for getting the difference between the other 2 formulas is not working, because I'm using the function of aggregattion, based on some characteristic, in order to have the max value of the date in one formula, and then have the min value of the date in other formula (the KF store for date is the same, that's the reason i have to use aggregation in order to calculate min and max value).
Then I have a third formula to calculate the difference between the min value and the max value, but it seems that its not working because of the aggregation.
Can you please give me some ideas of how can i obtain the desire result.
THANKS IN ADVANCEHi Carmonia,
(a) If you want to perform calculations on DATE and if both dates are characteristic infobjects, then you can go for Formula Replacement Path.
1. Create a New Formula or CKF and then select a Formula Variable. Right click and select New Varaible.
2. Now create a Variable for one of the Characteristic of Date type with processing type Formula - Replacement path. Select Replace with 'Key' and Dimension as 'Date'. Similarly create another formula replacement variable for another characteristic.
3. Now you can taken both these variables in calculations(such as A-B).
(b) If you are using key figure for the dates, then try by using DATE function in Data Functions of New Formula.
Example: DATE(kfig_MaxDate)-DATE(kfig_MinDate). Also try DATE(kfig1_MaxDate-kfig2_MaxDate).
***Assign points if useful.
Thanks,
Sasi -
Hi
I have one column which contains Date field. and I want date difference between two rows like (1st row- 2nd row),(2st row- 3nd row) 3-4,4-5 like that.
How I can get this
Thanks
Siddhartha PAs for the minutes calculation it doesn't take Einstein to know that the number of minutes in a day = 24 (hours) * 60 (minutes)
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as id, sysdate-10 as dt from dual union all
2 select 2, sysdate-7.4 from dual union all
3 select 3, sysdate-6.45 from dual union all
4 select 4, sysdate-2.82 from dual union all
5 select 5, sysdate from dual)
6 -- END OF TEST DATA
7 select id
8 ,dt
9 ,dt-lag(dt) over (order by id) as dt_diff_days
10 ,(dt-lag(dt) over (order by id))*(24*60) as dt_diff_minutes
11* from t
SQL> /
ID DT DT_DIFF_DAYS DT_DIFF_MINUTES
1 30/11/2007 13:07:37
2 03/12/2007 03:31:37 2.6 3744
3 04/12/2007 02:19:37 .95 1368
4 07/12/2007 17:26:49 3.63 5227.2
5 10/12/2007 13:07:37 2.82 4060.8
SQL> -
Date difference based on the conditions is giving wrong values
Hi,
In creating the formula for conditional date difference calculation,
i.e.,
if (sto date is 0) then (act date - mat rel date) else (sto date is not equal to 0) then (sto date - mat rel date)
So I tried with,
(sto date == 0) * (act date - mat rel date) + (sto date <> 0) * (sto date - mat rel date)
But I am getting a wrong value even with decimals as days can't be in decimals. Please suggest where I am going wrong in calculation.
Thanks,
Best Regards,
Darshan MSHi Darshan,
First of all, were the dates converted already to keyfigure?
If not, please check:
Convert a Characteristic into a Key Figure (BEx)
If they were already converted, try this:
(sto date == 0) * (act date - mat rel date) + (sto date - mat rel date)
Regards,
Loed -
Date difference problem.....
Hi,
I am calculating the date difference with the Formula variables.
My requirement is to find the rocords, where date difference is 0.
, Means same date.
But I am facing one problem while testing the query.
If for the two date , if both the columns are not having any value,
it contains # , and if I calculate the diffence of this,
This is also coming as 0 in the Date difference column.
Can somebody let me know how to rectify/avoid this situation?
Thanks , JeetuHi Jeetu,
According to your requirement, if record is there, there should be at leaset one date value say "Starting Date".
If "ending date" value is blank, the formula returns a junk/garbage value.
If both the date values are available, the formula returns the number of days corectly.
But, both the date values are blank, there should not be any record in such case. If you see this case in your data base,
that can be either wrong data record or you need to exclude such condition from your query.
Thanks,
Kiran. -
Hi
I have two date columns and I want one logical column which contains difference of those two DATE columns.
But I found that we dont have any Date difference or Date Add functions in OBIEE Answers.
Can anyone tell me any work around for the Date ADD/DIFF functions?
Thanks
RadhaOr if you want database specific date functions, use EVALUATE and then specify the database functions. Check my blog entry here http://oraclebizint.wordpress.com/2007/09/10/oracle-bi-ee-10133-support-for-native-database-functions-and-aggregates/
Thanks,
Venkat
http://oraclebizint.wordpress.com -
Date Difference between to date formula variable
Hi Expert,
I have create two formula variable one for Document Date and another one for Goods reciept date
and through formula variable I am subtracting these two formula variable and getting the no. of days between
document date and GR date.
This Shows me the correct value for one document date because i am filtering my query according to document
date,
while i am giving the date range for document date is shows me incorrect result. bucause document date formula
variable contains only one date.
Eg. i am giving the document date range like 01.02.2010 - 28.02.2010.
In document date formula variable it contains only 01.02..2010 and GR date formula variable it contain correct
value, thats why the date difference is incorrect because those PO which has PO date like 12.02.2010 for that Doc
formula variable bring the same date like 01.02.2010.
Please tell me the solution
Thanks and Regards
Lalit KumarHi Expert,
Actually i have created two formula variable on for PO date and another for GR date
and i've restrict the query through PO date.
while i am taking the single PO date in Selection parameter it showing me correct difference
eg: Selection Parameter for PO: 01.01.2010
But while i am taking the date interval for PO date
eg: 01.01.2010-30.01.2010
PO No: XXXXX123 , Doc date: 01.01.2010 GR date: 7.01.2010 then date difference is : 6
PO No: XXXXX432, Doc date: 03.01.2010 GR date: 8.01.2010 then date difference is : 7 but it is 5
Thanks and Regards
Lalit Kumar -
HI,
I ran a query on a database few times which had different execution plan (basically first I ran with index and later without index).
I tried to cross verify the data from DBA_HIST_SQLSTAT and DBA_HIST_ACTIVE_SESS_HISTORY for that particular query and found there were two different SQL ID for same SQL statement. Ideally if execution plan changes then only the plan hash value or hash value changes but in this scenario we have two different SQL ID with different Plan hash value or hash value.
I need to understand why do we have this data difference?
==================================================================================================
SQL> select snap_id,instance_number,sample_time,session_id,module,sql_plan_hash_value from dba_hist_active_sess_history where sql_id='9zgyc24gzsgpz';
SNAP_ID INSTANCE_NUMBER SAMPLE_TIME SESSION_ID MODULE SQL_PLAN_HASH_VALUE
9478 2 07-JAN-11 13.09.11.540 503 SQL*Plus 2290340548
9478 2 07-JAN-11 13.23.42.616 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.25.12.735 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.25.22.746 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.25.32.759 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.25.42.770 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.25.52.782 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.26.02.795 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.26.12.811 514 SQL*Plus 3778028574
9478 2 07-JAN-11 13.26.22.823 514 SQL*Plus 3778028574
SQL> select snap_id,sql_id,plan_hash_value from dba_hist_sqlstat where sql_id='9zgyc24gzsgpz' ;
SNAP_ID SQL_ID PLAN_HASH_VALUE
9478 9zgyc24gzsgpz 2290340548
==================================================================================================
Thanks
DevendraHi,
DBA_HIST_ACTIVE_SESS_HISTORY is a sampling of the sampling already done in ASH, however data used for AWR "snapshots" is completely separate and works just like Statspack did, so it can capture all SQL in the shared pool at the time of the snapshot if you tell it to - it is not limited to just the SQL sampled by ASH. Also AWR does not capture every statement executed in the interval,even if the statement was not aged out from V$SQL.
DBA_HIST_ACTIVE_SESS_HISTORY displays the history of the contents of the in-memory active session history of recent system activity, DBA_HIST_SQLSTAT displays historical information about SQL statistics
Regards,
Ugur -
How we calculate the date difference between two list in SharePoint 2010
Hi friend's....I have two list first is list1. In this list i have two coulmn start_date and End_date. In second list2 i have two column HolidayName and Holiday_date. Now i want two find the number of day in list1 Excluding Weekend and Holiday_date(that
column from list2). How i will do ..? Please help me dosto..Thanks for reply...
I have done the date difference in list1. But i want to Exclude the Holiday_date form list2.
I have list1 - Start_date , End_date, Number_of_day(Exclude weekend and Holiday_date between Start_date and End_date )
list2 - HolidayName, Holiday_date
Now how i will calculate the Number_of_day in first list. -
Date difference between Requsition apporval and Po approval in Oracle apps
My requirement is that l need to get the number of date difference between requisition apporval date(requisition) and po approval date (purchase) excluding holidays how to do it ?
Thanks in advance..One PO could be generated from multiple requisitions. In that case, which requisition would you like to consider?
One requisition could be converted into multiple POs. In that case, which PO would you like to consider?
Assuming, there is a one-to-one relationship between your POs and requisitions:
Link a PO to the corresponding requisition by joining po_distributions_all.req_distribution_id with po_req_distributions_all.requisition_id
Once you have found the 2 records, get the approved_date from po_headers_all and po_requisition_headers_all
Then go to bom_calendar_dates for those dates and find the difference between seq_num. That is what you are looking for.
Sandeep Gandhi -
Date Difference in same column
select to_char(CREATEDON,'DD-MM-YYYY HH24:MM:SS'),LABSTATUS,REMARKS from history_paperlesstran
where hnum='797551D' order by to_char(CREATEDON,'DD-MM-YYYY HH24:MM:SS');
Rownum TO_CHAR(CREATEDON,' LABSTATUS REMARKS
1 20-10-2010 08:10:08 1 Barcode number generated and printed
2 20-10-2010 08:10:08 1 Barcode number generated and printed
3 20-10-2010 08:10:08 1 Barcode number generated and printed
4 20-10-2010 08:10:08 1 Barcode number generated and printed
5 20-10-2010 08:10:08 1 Barcode number generated and printed
6 20-10-2010 08:10:08 1 Barcode number generated and printed
7 20-10-2010 09:10:55 3 Recieved in department
8 20-10-2010 09:10:58 3 Recieved in department
9 20-10-2010 09:10:58 3 Recieved in department
10 20-10-2010 09:10:58 3 Recieved in department
11 20-10-2010 09:10:58 3 Recieved in department
12 20-10-2010 10:10:38 3 Recieved in department
13 20-10-2010 11:10:34 1 Barcode number generated and printed
14 20-10-2010 11:10:34 1 Barcode number generated and printed
15 20-10-2010 11:10:35 3 Recieved in department
16 20-10-2010 12:10:08 3 Recieved in department
17 20-10-2010 14:10:03 1 Barcode number generated and printed
18 20-10-2010 14:10:44 3 Recieved in department
18 rows selected.
Dear Friends, Now i want to get the date difference on labstatus based,i.e rownum1 - rownum7, rownum2 - rownum8, and rownum17 - rownum18
Thing is Barcode number generated and printed - Recieved in department for each & every samples.
Advance thanks for your solution...
Edited by: bharathit on Oct 21, 2010 2:18 AMYou mean something like this?
SQL> ed
Wrote file afiedt.buf
1 with t as (select 1 as rn, to_date('20-10-2010 08:10:08', 'DD-MM-YYYY HH24:MI:SS') as dt, 1 as labstatus, 'Barcode number generated and printed' as comments from dual union all
2 select 2, to_date('20-10-2010 08:10:08','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
3 select 3, to_date('20-10-2010 08:10:08','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
4 select 4, to_date('20-10-2010 08:10:08','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
5 select 5, to_date('20-10-2010 08:10:08','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
6 select 6, to_date('20-10-2010 08:10:08','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
7 select 7, to_date('20-10-2010 09:10:55','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
8 select 8, to_date('20-10-2010 09:10:58','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
9 select 9, to_date('20-10-2010 09:10:58','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
10 select 10, to_date('20-10-2010 09:10:58','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
11 select 11, to_date('20-10-2010 09:10:58','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
12 select 12, to_date('20-10-2010 10:10:38','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
13 select 13, to_date('20-10-2010 11:10:34','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
14 select 14, to_date('20-10-2010 11:10:34','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
15 select 15, to_date('20-10-2010 11:10:35','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
16 select 16, to_date('20-10-2010 12:10:08','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual union all
17 select 17, to_date('20-10-2010 14:10:03','DD-MM-YYYY HH24:MI:SS'), 1, 'Barcode number generated and printed' from dual union all
18 select 18, to_date('20-10-2010 14:10:44','DD-MM-YYYY HH24:MI:SS'), 3, 'Recieved in department' from dual)
19 --
20 -- END OF TEST DATA
21 --
22 ,x as (select rn, dt, labstatus, comments, row_number() over (partition by labstatus order by rn) as labrn from t)
23 --
24 select y.rn as rn1, y.dt as dt1, z.rn as rn2, z.dt as dt2, round((z.dt - y.dt)*24*60) as mins_diff
25 from x y join x z on (y.labrn = z.labrn)
26 where y.labstatus = 1
27* and z.labstatus = 3
SQL> /
RN1 DT1 RN2 DT2 MINS_DIFF
1 20/10/2010 08:10:08 7 20/10/2010 09:10:55 61
2 20/10/2010 08:10:08 8 20/10/2010 09:10:58 61
3 20/10/2010 08:10:08 9 20/10/2010 09:10:58 61
4 20/10/2010 08:10:08 10 20/10/2010 09:10:58 61
5 20/10/2010 08:10:08 11 20/10/2010 09:10:58 61
6 20/10/2010 08:10:08 12 20/10/2010 10:10:38 121
13 20/10/2010 11:10:34 15 20/10/2010 11:10:35 0
14 20/10/2010 11:10:34 16 20/10/2010 12:10:08 60
17 20/10/2010 14:10:03 18 20/10/2010 14:10:44 1
9 rows selected.
SQL> -
Date difference is not showing the correct result for date interval
Hi Expert,
I've created two formula variable one for PO date and another for GR date
while i am taking the date difference of GR and PO date for single PO date selection
it showing me correct result , but while i am taking the date interval for PO date it not
showing the correct result.
eg: PO date: 01.01.2010 for a particular PO and Gr date is suppose 03.01.2010, 06.01.2010
it showing the result 2 and 5.
But if i am taking date interval for PO date:
eg: 01.01.2010 - 31.01.2010
PO date: 10.01.2010 and GR date are suppose 15.01.2010, 22.01.2010 and 30.01.2010
it showing me 14, 21 and 29
Thanks and Regards
Lalit KumarHi Expert,
Through replacement path.
Thanks and Regards
Lalit Kumar
Maybe you are looking for
-
Summary: I have installed Windows 7 Ultimate x64 on my G580. Everything is working fine except the WLAN driver fails to install with the error "BCM4313: Can not find setup file". Details: I bought lenovo G580 with Windows 8. Since my parents are no
-
Photoshop CS5 Color Management
My question has a complicated back story, but here is where I'm at. I'm still a newby when it comes to color management. I'm running Photoshop CS5, Lightroom 3.3, Windows 7 64-bit, Dell Studio XPS desktop, and a new Dell U2311H monitor. I really s
-
I downloaded the Photoshop CC on my computer but it's asking for a serial number and I never got one
-
Disk Utility assigns incorrect identifier to external drive
Hi, I am running 10.7.5, I backup my notebook to a 500GB drive using Time Machine, after a recent backup my 2TB drive is labled as the 500GB BACKUP drive in disk utility and not mounted under finder. I tried everything. I am unable to unmount the d
-
I update my iphone4 to ios7 .but my phone locked and message sim invalid.how can i unlocked it.