Find difference between date
I need to know how i can find difference between date
like Joining date: 01-jan-2009 Today 10-jan-2010 result will be "1 year 10 days"
I need it in Oracle forms 6i. plz help me...
Hi,
In oracle forms you can use
RESULT :=
TRUNC ((:date2 - :date1 + 1) / 365)
|| ' year and '
|| MOD (:date2 - :date1 + 1, 365)
|| ' days';
in sql you can use
SELECT TRUNC ((:date2 - :date1 + 1) / 365)
|| ' year and '
|| MOD (:date2 - :date1 + 1, 365)
|| ' days'
FROM DUAL;
Similar Messages
-
User defined function to find difference between dates
format of dtActivityStartDate/dtActivityFinishDate: 2010-09-17 14:50:51.150
usdFuncTimeCalc (vcActivityName,dtActivityStartDate, dtActivityFinishDate) -- user defined function
i need to calculate time elapsed for that type of activity following are the rules:
(If Process Request is the activity)
Working Days: Monday through Saturday
Hours of Operation: 9AM – 5PM
only working hours of day need to the counted like for example if it is sep 15 11 Am is dtActivityStartDate & Sep 17 is dtActivityFinishDate is 10 Am. then time elapsed is 11am to 5pm on sep 15 , 9 to 5 on sep 16 & 9 to 10 on sep 17 so total should be
6+ 8 + 1 = 15 hours + minutes.
format of date time: 2010-09-17 14:50:51.150
vcActivityName = Process Request
Don't worry about process request...I hv modified the code to make it more generic inorder to suit any timings (customizable) from Monday - Saturday.
declare
-- ** b u s i n e s s _ h o u r s **
-- business_hours returns the number of work houts (9 am through 5 pm,
-- Monday through Saturday) between in_start_dt and in_end_dt.
-- If in_start_dt > in_end_dt, the results will be <= 0.
-- Holidays are not considered.
in_start_dt DATE := to_date('15-SEP-2010 11:00:00','DD-MON-RRRR HH24:MI:SS');
in_end_dt DATE := to_date('17-SEP-2010 10:00:00','DD-MON-RRRR HH24:MI:SS');
d NUMBER; -- Hours of either start_dt or end_dt after midnight
end_dt DATE := GREATEST(in_start_dt, in_end_dt); -- In case dates were in wrong order
return_val NUMBER; -- Total number of working hours
start_dt DATE := LEAST(in_start_dt, in_end_dt); -- In case dates were in wrong order
start_time number := 9;
end_time number := 17;
BEGIN
WITH all_days AS(
SELECT start_dt + LEVEL - 1 AS a_dt
FROM dual
CONNECT BY LEVEL <= 1 + TRUNC(end_dt) - TRUNC(start_dt))
--SELECT SUM(12)
SELECT SUM(end_time-start_time)
INTO return_val
FROM all_days
WHERE TO_CHAR(a_dt,'Dy','NLS_DATE_LANGUAGE = ''ENGLISH''') NOT IN ('Sun');
dbms_output.put_line('Return_Val_1 : '||return_val);
-- Adjust hours from start_dt, if necessary
IF TO_CHAR(start_dt, 'Dy', 'NLS_DATE_LANGUAGE = ''ENGLISH''') NOT IN ('Sun') THEN
-- Calculate nbr of hours passed from midnight
d := 24 * (start_dt - TRUNC(start_dt));
dbms_output.put_line('d:'||d);
IF d >= end_time THEN -- d has passed 5 PM (end_time)
-- Don't count start_dt if it has passed the closing hours
return_val := return_val - (end_time-start_time);
dbms_output.put_line('if-d:'||return_val);
ELSIF d > start_time and d < end_time THEN -- d has passed 9 AM but less than 5 PM
-- Don't count the part of start_dt which has passed the opening hours
return_val := return_val - (d - start_time);
dbms_output.put_line('else-d:'||return_val);
END IF;
END IF;
dbms_output.put_line('');
dbms_output.put_line('Return_Val_2 : '||return_val);
-- Adjust hours from end_dt, if necessary
IF TO_CHAR(end_dt, 'Dy', 'NLS_DATE_LANGUAGE = ''ENGLISH''') NOT IN ('Sun') THEN
d := 24 * (end_dt - TRUNC(end_dt));
dbms_output.put_line('d:'||d);
IF d <= 9 THEN -- d < 9 AM
-- Don't count end_dt itself
return_val := return_val - (end_time-start_time);
dbms_output.put_line('if-d:'||return_val);
ELSIF d > start_time and d < end_time THEN -- d > 5 PM
-- Don't count part of end_dt
return_val := return_val - (end_time - d);
dbms_output.put_line('else-d:'||return_val);
END IF;
END IF;
dbms_output.put_line('');
dbms_output.put_line('Return_Val_3 : '||return_val);
IF in_start_dt > in_end_dt THEN
return_val := -return_val;
END IF;
dbms_output.put_line('');
dbms_output.put_line('Return_Val_4 : '||return_val);
END;Plz note the following points of the code :
1) You'll need to convert it a function, I just made it a declare..begin..end; block.
2) I hv used the same timings for start & end as you hv mentioned.
3) The 2 variables "start_time" and "end_time" take the opening & closing business hours respectively in a 24 hour format.
4) You might want to remove the DBMS_OUTPUT ... stmts which I had added for debugging.
It was an interesting code block to analyze ... :-) -
Finding difference between 2 databases
Hi Folks,
I have the following problem:
I have 2 databases, database old, database new. Database new has modified/removed/added/inserted rows. Also columns in the db can also be modified. So what I have to do is to find the set of SQL statements which if I execute on database old, will make database old same as database new. Modification is only in data, not triggers etc.,
I have explained my manager that this is not very easy to implement. Even finding difference between 2 DB is not trivial. Do you guys have any suggestion for me? whether in terms of implementing it or even convincing my boss is fine :)
Are there any open source tools to do this? I am in big trouble now :(
Thanks,Unless there is some other goal that you have not mentioned this is fairly easy.
Just delete all the tables from the old database using SQL delete tables and then create new tables and populate them with data from the new database.
Your SQL is basically just a serialization of the data in your new database.
Anything else that you could do, such as calculating the differences from the one database to the other, and then creating a minimal edit list that will make the least possible number of changes must be weighed against the time it will take to write the code to compute the differences, the time it will take to debug the code and convince yourself that it is doing the right thing, and the time it will take to actually run. -
Hi Gurus,
Can anyone tell me the difference between "Data replication", "Data Cloning", "Data duplication" and "Data Migration". I have gone through Google but doesn't find any appropriate answer for that where I can find the difference.
It would be highly appreciated if you give me a link for all and give me some point out.
Thanks & Regards
Nimai KarmakarHere is how I see the terms used and understood by most folks
"Data replication"
This is the keeping the same data in sync in 2 different databases. Replication is the process of keeping data in sync between 2 environments/databases and not limited to Oracle to Oracle, it could be Oracle to MySQL to be kept in sync, MySQL to Oracle, Oracle to SQL Server, SQL Server to Oracle. The purpose of keeping data in sync can vary, but that is basic description of what it is.
"Data Cloning"
Make a copy of the data/database from one database environment to another, like for example taking production database and cloning the database to a pre-production database/environment for testing. Coning term is used more when copying a database not just data, but the whole database so typically you hear the reference "Database Cloning", but data cloning is basically the making a copy of the data from one place to another. Sometimes Cloning and Duplicating are used in the same way by folks as the basic end result is the same you are making a copy of the data to someplace else.
"Data duplication"
This is typically term when duplicating the data from one environment to another for a particular purpose, a lot of folks use "Data/Database Cloning" and "Data Duplication" in the same context, meaning they use them to mean the same thing, but I see more difference in the terms so when they are different Data Duplication is done when combining 2 databases to 1 therefore you can not clone the 2 databases into one so this term would be used more in those circumstances.
"Data Migration"
Moving data from one location/database to another location database, for example moving from MySQL to Oracle you would do a data migration from MySQL to Oracle as you are moving the data from MySQL to Oracle and going to leave it in Oracle. You could also be migrating to from Oracle 10g environment to a new Oracle 11g environment, therefore "Migration" is typically used when referring to moving the data from one environment to another and the source and target are different in location, database vendor, database version.
These are very simple ways of looking at the terms from my experience on how they are used. -
What is difference between data base structure and stucure in program
what is difference between data base structure and stucure declared in program level . can explain cleary if knows
Hi,
Data base structure is global decalaration you can reffer this structure in any of your developments, when ever you cahange this structure the changes automatically will get updated in all the programs.
coming to structures in program it is local to your program only, if you want to change the structure again you have to open the program and do the necessary changes.
Reward if useful.
Thanks,
Sreeram. -
Difference between Data staging and Dimension Table ?
Difference between Data staging and Dimension Table ?
Data Staging:
Data extraction and transformation is done here.
Meaning that, if we have source data in flat file, we extract it and load into staging tables, we take care of nulls, we change datetime format etc.. and after such cleansing/transformation at then end, load it to Dim/Fact tables
Pros: Makes process simpler and easy and also we can keep track of data as we have data in staging
Cons: Staging tables need space hence need memory space
Dimension Table:
tables which describes/stores the attribute about specific objects
Below is star schema which has dimension storing information related to Product, Customer etc..
-Vaibhav Chaudhari -
Difference between date info object in characteristics and keyfigure
What is the difference between "date" data type in characteristic and keyfigure?
Thanks in advance.
RajHi Rajasekhar,
If date is characteristics,query can be analysed based on date and filters can also be set using this date.
If it is key figure query cannot be analysed based on date,
Based on requirements,we have to decide whether it should be chatracteristic or key figure
Regards
Prakash -
Hi,
I need to create a counter kf which should populate 1 and 0 to this counter field. Please let me know is there any difference between data type
NUMBER (DEC) and INTEGER (INT4).
Please suggest.
Thanks & Regards,
Pavan kumarHi Pavan,
The basic difference between Number(DEC) and INT4 is its internal storage in system.
For Number (DEC) - Value internally stored as packed number with 3 decimal places whereas INT 4 as 4 byte integer without decimal places.
For counter KF, you can go for INT 4.
Hope this helps.
Thanks -
Find Differences between two tables at column level
Hi,
I have 2 tables one live table and the other History table..
If i have to find differences between live table and the latest version in the History table and also find which column got chaanged
How would i do that for a table which has many columns and i need each column for which the value has changed for a id
for ex:
Table 1 (LIve) Table 2 (History)
ID col1 col2 Version ID col1 col2 Version
1 ABC 123 V1 1 ABCD 123 v2
2 NBS 1234 V1 2 NBS 123 V2
Result set should be
Result Set:
ID col which changed
1 col1
2 col2
Because the values for that column had been changed
Except gives me all the differences not just the column level ..The dynamic version using schema views... :D
--Build a coulple OF testing tables to play with
CREATE TABLE dbo.Table1 (
ID INT IDENTITY(1,1) PRIMARY KEY,
Col1 INT,
Col2 INT,
Col3 INT
CREATE TABLE dbo.Table2 (
ID INT IDENTITY(1,1) PRIMARY KEY,
Col1 INT,
Col2 INT,
Col3 INT
INSERT dbo.Table1 (Col1,Col2,Col3) VALUES
(123,456,789),
(111,222,333),
(444,555,666),
(777,888,999),
(321,345,769),
(179,753,758),
(362,362,236),
(856,874,896),
(821,729,324)
INSERT dbo.Table2 (Col1,Col2,Col3) VALUES
(123,456,789),
(111,999,333), --col2 diff
(444,555,666),
(777,888,999),
(321,345,123), --col3 diff
(179,753,758),
(362,362,236),
(234,874,896), --col1 diff
(821,729,324)
And then the actual solution...
DECLARE
@t1 VARCHAR(10) = 'Table1',
@t2 VARCHAR(10) = 'Table2'
IF OBJECT_ID('tempdb..#temp') IS NOT NULL DROP TABLE #temp
SELECT
c.TABLE_SCHEMA,
c.TABLE_NAME,
c.COLUMN_NAME,
c.ORDINAL_POSITION,
CASE WHEN u.COLUMN_NAME IS NOT NULL THEN 1 ELSE 0 END AS PK
INTO #temp
FROM
INFORMATION_SCHEMA.COLUMNS c
JOIN INFORMATION_SCHEMA.TABLES t
ON c.TABLE_NAME = t.TABLE_NAME
AND c.TABLE_SCHEMA = t.TABLE_SCHEMA
LEFT JOIN INFORMATION_SCHEMA.KEY_COLUMN_USAGE u
ON c.COLUMN_NAME = u.COLUMN_NAME
AND c.TABLE_NAME = u.TABLE_NAME
AND c.TABLE_SCHEMA = u.TABLE_SCHEMA
AND OBJECTPROPERTY(OBJECT_ID(constraint_name), 'IsPrimaryKey') = 1
WHERE 1 = 1
AND t.TABLE_TYPE = 'BASE TABLE'
AND c.TABLE_NAME IN (@t1,@t2)
ORDER BY
c.TABLE_SCHEMA, c.TABLE_NAME, c.ORDINAL_POSITION
DECLARE @select VARCHAR(MAX)
SELECT @select = COALESCE(@select + ', ', '') + t.TABLE_SCHEMA + '.' + t.TABLE_NAME + '.' + t.COLUMN_NAME
FROM #temp AS t
ORDER BY t.TABLE_NAME, t.ORDINAL_POSITION
DECLARE @from VARCHAR(MAX)
SELECT @from = COALESCE(@from + ' FULL JOIN ', '') + t.TABLE_SCHEMA + '.' + t.TABLE_NAME
FROM #temp AS t
WHERE t.PK = 1
ORDER BY t.TABLE_NAME
DECLARE @on VARCHAR(MAX)
SELECT @on = COALESCE(@on + ' = ', '') + t.TABLE_SCHEMA + '.' + t.TABLE_NAME + '.' + t.COLUMN_NAME
FROM #temp AS t
WHERE t.PK = 1
ORDER BY t.TABLE_NAME, t.ORDINAL_POSITION
DECLARE @where VARCHAR(MAX)
SELECT @where = COALESCE(@where + CASE WHEN t.TABLE_NAME = @t1 THEN ' OR ' ELSE ' <> ' END, '') + t.TABLE_SCHEMA + '.' + t.TABLE_NAME + '.' + t.COLUMN_NAME
FROM #temp AS t
WHERE t.PK = 0
ORDER BY t.ORDINAL_POSITION, t.TABLE_NAME
DECLARE @sql VARCHAR(MAX) = '
SELECT ' + @select + '
FROM ' + @from + '
ON ' + @on + '
WHERE ' + @where
EXEC (@sql)
HTH,
Jason -
Difference between data target & Infoprovider.
Hi all,
Difference between data target & Infoprovider.
why cube is best in performance wise other than ods,multiproviders.
Thanks,
cheta.A data target is an object into which data is loaded. Data targets are the physical objects relevant during data modeling and when loading the data.
Structure
Data targets are:
InfoCubes
ODS objects
InfoObjects (characteristics with attributes, texts or hierarchies).
There are differences between:
Pure data targets for which no queries can be created or executed. An InfoCube might only be used as a data source for another InfoCube. This is also possible for ODS objects and InfoObjects.
If you want a characteristic to appear in the InfoProvider tree, you have to assign an InfoArea to it. You can define update rules for the characteristic in the InfoProvider tree, and use them to load attributes and texts.
You can turn a characteristic into a data target only if the characteristic contains texts or attributes. It is not possible to use update rules to load hierarchies.
Data targets for which queries can be defined. These are called InfoProviders.
<Request for points removed>
Regards
Hemant
Message was edited by:
Moderator -
Difference between Data Class and Delivery Class
What is the Difference between Data Class and Delivery Class , what happens Phisically to the Data .
Moderator message: what is the difference between your question and a question that we'd welcome here in the forums?
[Rules of engagement|http://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement]
Edited by: Thomas Zloch on Nov 22, 2010 1:17 PMWhat is the Difference between Data Class and Delivery Class , what happens Phisically to the Data .
Moderator message: what is the difference between your question and a question that we'd welcome here in the forums?
[Rules of engagement|http://wiki.sdn.sap.com/wiki/display/HOME/RulesofEngagement]
Edited by: Thomas Zloch on Nov 22, 2010 1:17 PM -
Difference between Data Provider and extractor.
Hi
Can someone help me in understanding difference between data providers and data extractor.
I have gone through some documents but not able to get the exact difference between them.
What is the exact role of data provider and extractor with respect to sap solution manager.
Is data provider== Data extractor?
Thanks,
VijayHello Vijaya,
From my perspective the Data Providers are responsible for collecting metric values from the monitored objects on the managed sources systems and sending these to the Solution Manager Monitoring and Alerting Infrastrucure.
Data extractors on the other hand are the reporting objects which are defined on the BW part of Solution Manager and can be enabled by configuring some monitoring scenario's. Once these data extractors are enabled, they will use the data from the "Data Providers" (see above) to setup nice BW reportings on the Solution Manager monitoring dashboards.
I hope this answer helps you. -
Difference between Dates: BW Query???
Hello all,
A.I have to get the difference between dates i.e Date1 and Date2.
I have used a 2 formula variables for each one of them with Replacement path - Key - number as the settings.
When i execute the difference between the 2 formula variables, i get inconsistent results if the dates are from 2 different months.
Example(Correct Result)
Date1 = 14.02.2005
Date2 = 10.02.2005
Result = 4
Example(Incorrect Result)???????
Date1 = 14.02.2005
Date2 = 10.01.2005
Result = 104
Iam know that system is converting the date as a number like 20040214 and 22040110 and just substracts.....This is not correct....any solution to circmvent this problem???
B.If iam using a user-exit for variables, how to pass the values Date1 and Date2 to user-exit so that i can calculate the difference of days using a function module.
I know how to use a user-exit but not sure about working on 2 fields at a time for a formula variable????1) For the first problem, I think you should play with the replacement path settings (type, offset,...). I did this before and I'm sure it worked.
2) If the variables are entered in the variable screen there is no problem to use a function module (it works with steps --> look at the how-to), but I think you want to calculate not on variables but on the keyfigure values itself, in this case you will have to use virtual characteristics. There is also a how-to about this, I can't help you with the details my self.
kr,
Tom -
Difference Between data target and infoprovider
Hi Experts,
I am new to BW
What is the difference between data target and infoprovider
Thanks and Regards,
saveenHi Saveen,
InfoProvider is an object on which BEx queries are created. It provides information (data) to the queries when they are executed. InfoProviders may contain data (like cube) or may not contain data (like multiproivder and InfoSet).
Data Target is an object to which you will load the data, like cube, ODS or InfoObject. But it is not necessary that each data target is an InfoProvider...like you may have ODS objects that are not enabled for reporting, but you are loading data to them for staging purpose.
Hope this helps... -
Whats basic difference between data and types while declearing the itab
whats basic difference between data and types while declearing the internal tables...
DATA : BEGIN OF t_vbap OCCURS 0,
vbeln1 LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
kwmeng LIKE vbap-kwmeng,
netpr LIKE vbap-netpr,
netwr LIKE vbap-netwr,
werks LIKE vbap-werks,
matnr LIKE vbap-matnr,
arktx LIKE vbap-arktx,
END OF t_vbap.
vs
TYPES : BEGIN OF t_vbap,
vbeln1 LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
kwmeng LIKE vbap-kwmeng,
netpr LIKE vbap-netpr,
netwr LIKE vbap-netwr,
werks LIKE vbap-werks,
matnr LIKE vbap-matnr,
arktx LIKE vbap-arktx,
END OF t_vbap.
and vs
TYPES : BEGIN OF t_vbap,
vbeln1 LIKE vbeln,
posnr LIKE posnr,
kwmeng LIKE kwmeng,
netpr LIKE netpr,
netwr LIKE netwr,
werks LIKE werks,
matnr LIKE matnr,
arktx LIKE arktx,
END OF t_vbap.hi,
like -> used for refering existing data elements in data dictionary or in sap
type -> used for refering existing data types in sap.
types: used for creating used defined structure of tables which has fields from more tahn one table.
diff b/w types and type in creation of internal tables is that when u create a table with types then u can use same for work area creation also.
ex:
TYPES : BEGIN OF t_vbap,
vbeln1 LIKE vbeln,
posnr LIKE posnr,
kwmeng LIKE kwmeng,
netpr LIKE netpr,
netwr LIKE netwr,
werks LIKE werks,
matnr LIKE matnr,
arktx LIKE arktx,
END OF t_vbap.
data: itab1 type t_vbap
wa_itab1 type t_vbap.
when type is used then u have to create a defintion of work area for another time when internal table doesnt have headr line as
ex:
DATA : BEGIN OF t_vbap OCCURS 0,
vbeln1 LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
kwmeng LIKE vbap-kwmeng,
netpr LIKE vbap-netpr,
netwr LIKE vbap-netwr,
werks LIKE vbap-werks,
matnr LIKE vbap-matnr,
arktx LIKE vbap-arktx,
END OF t_vbap.
DATA : BEGIN OF wa_vbap,
vbeln1 LIKE vbap-vbeln,
posnr LIKE vbap-posnr,
kwmeng LIKE vbap-kwmeng,
netpr LIKE vbap-netpr,
netwr LIKE vbap-netwr,
werks LIKE vbap-werks,
matnr LIKE vbap-matnr,
arktx LIKE vbap-arktx,
END OF wa_vbap.
if helpful reward soem points.
with regards,
suresh.
Maybe you are looking for
-
Make a read-only text field open by using button and javascript
Hello I have a form with text fields that I will pre-populate with data. The text fields will be read-only by default. I want to make it so that when a user wants to make edits, he will need to click on a button and in turn, the text field's backgrou
-
Tried to check on updates for CS6 64 bit - Received message saying application manager may be damaged - download and install new copy - when I try this I receive message ERROR 404 I have a PC - any help would be gratefully received - thanks - William
-
Hi, When I insert text in Photoshop, my cursor does not follow the text - it just stays at the beginning of the line. All letter are added correctly but when I add a character such as @ # $ & * etc, it automatically gets placed at the beginning of th
-
when the new fire fox change kicked in I lost some of my add on apps such as ani weather, ant video down loader, and flash & video down loader, how do I get them back? I tried reinstalling them but they don't show up in the tool bar.
-
Detail business flow for sd and mm
any body have the business flow for the sd and mm . please give me the link............if other modules also these ple pass the link ......