Subtracting between two dates and see the result as a date
HII everyone,I had to create a procedure that checks the difference of dates in one month...
I've got is the view of the difference in the form of date itself...
for example:
01/03/2012
01/03/2012
01/03/2012
01/05/2012
01/05/2012
.
.
so now for a full month...
the output should be as data are missing for the date 01/04/2012...
is it possible to display the output as given...
I am new to oracle, help would be much appreciated...
Thank you..
Published by: 948895 on August 2, 2012 21:39
To fill the gaps between the two dates:
select &&start_date + (level - 1)
from dual
connect by level <= (&&end_date - &&start_date)
/
To generate the dates for one month:
select trunc(&&start_date, 'MM')) + (level - 1)
from dual
connect by level <= to_number(to_char( last(day(&&start_date)))
/
This example uses SQL * more variable substitution, but you can easily change to use the value of PL/SQL or everything that you need.
Cheers, APC
Tags: Database
Similar Questions
-
Add the value of point two apex and display the result in another part of the apex
Hello
I need to make the addition of the two item values using apex.item.text and find the result in another apex.item.text.
For example:
please suggest meSELECT
apex_item. Text(1,null) ONE
apex_item. Text(2,null) TWO
apex_item. Text(3,null) RESULT
FROM EMP
Thank you
Sudhir>
No it does not add the two values in the column, user key to enter the value, it must add the value of the item and displays the result in a dynamic way. Need a suggestion for using javascript
>
This requirement was not not clear in the op.See the demo of Denes Kubicek.
This topic is discussed far too often. Have you tried to Oracle Application Express (APEX) and adapting one of the many examples of LoV cascading to your situation?
See you soon,.
PS: Tip:
Look for the p_item_id and p_attributes of the APEX_ITEM API parameters.
You can call JS functions for example using p_attributeAPEX_ITEM.TEXT(... p_attributes => 'onchange="doTotal(this);"', /* doTotal being your JS Function */ ...
Published by: Dominic August 16, 2012 11:52
-
Subtract two time_clock and get the result minutes
Hi Experts,
Nicely, I would subtract two type of time_clock that varcahr2 to the database and get the minutes of the result.
Data:
Select ' 08:00 ' as start_time_clock, 15:00 ' as the double end_time_clock
Union of all the
Select ' 09:00 ', 16:30 ' of the double
Expected result:
start_time_clock end_time_clock count_minutes
---------------- -------------- -------------
08:00 15:00 420
09:00 16:30 450
Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - production
Thanks in advance
WITH dataset
AS (SELECT ' 08:00 ' AS start_time_clock, 15:00 ' AS end_time_clock)
OF THE DOUBLE
UNION ALL
SELECT ' 09:00 ', 16:30 ' DOUBLE)
SELECT (to_date (end_time_clock,'HH24:MI')-to_date(start_time_clock,'HH24:MI')) * 24 * 60))
Of THE dataset
-
How to add two fields and show the result in a third
All,
I have 2 InputText field; both are related to the fields of the associated database.
I want to display the sum of these two fields on a text output.
I declare the value of the output in this way text link:
#{sessionScope.PersonalNrBean.summeDB.value + sessionScope.PersonalNrBean.kmGeldMlp.value}
But I get this error:
Cannot find resource for bundle java.util.PropertyResourceBundle, key el.convert
ADF_FACES - 60097:Weitere desKomitees find DEM Fehlerlog einen entry as servers, der mit: ADF_FACES - 60096:Server - Exception while PPR, beginnt #3
If I declare the value binding to contain the field even two times:
#{sessionScope.PersonalNrBean.summeDB.value + sessionScope.PersonalNrBean.summeDB.value}
It works as expected, but it's not really what I need...
Any ideas?
Thanks in advance,
Sergio.
Edited by: user5414451 the 14.07.2011 02:57Try following:
#{bindings.summeDB.inputValue.value + bindings.kmGeldMlp.inputValue.value}
Jean Lou
-
Hello experts...
I'm new to this forum and Oracle coding complex.
I have a task in which I want to compare two tables with the same structure, same columns. My Oracle database is 11g Release 2. I want this column-by-column comparison and save the result in a separate table. (say result_table)
The structure of the table would be as follows:
SQL > desc emp;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NOT NULL NUMBER 4
ENAME VARCHAR2 (10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER (2)
SQL > emp_comp desc;
Name Null? Type
----------------------------------------- -------- ----------------------------
EMPNO NOT NULL NUMBER 4
ENAME VARCHAR2 (10)
JOB VARCHAR2(9)
MGR NUMBER(4)
HIREDATE DATE
SAL NUMBER(7,2)
COMM NUMBER(7,2)
DEPTNO NUMBER (2)
Both of the tables EMPNO is the primary key.
I want to compare these two tables based on the EMPNO (EMPNO even is both tables).
The result log table would be as follows:
SQL > create table result_table
2 (check_sr_no, number (5),)
table_name 3 varchar2 (30),
ROW_ID 4 varchar2 (20).
column_name 5 varchar2 (20).
6 column_data varchar2 (1000).
compared_by 7 varchar2 (10));
Table created.
SQL > alter table result_table
2 Add the constraint result_table_pk
3 primary key (check_sr_no);
Modified table.
The name of the table and the name of the column will not be hardcoded (based parameter by user)
I tried to use the dbms_comparison package, but do not find comparison of column to column.
I also used by using the query operator LESS. It's showing the difference in rank.
I also went to https://asktom.oracle.com/pls/apex/f?p=100:11:0:P11_QUESTION_ID:2151582681236
Your help will be very appreciated.
Thank you
DK
Tom Kyte has answered this question MANY times over the years. Here are links for its solution
https://asktom.Oracle.com/pls/Apex/f?p=100:11:0:P11_QUESTION_ID:4934799800346640847
-
How to get the date between two dates, except Saturday and Sunday
Dear all,
The query above returns the following outputselect to_date('25-04-2012', 'DD-MM-YYYY') + rownum -1 dt from dual connect by level <= to_date('05-05-2012', 'DD-MM-YYYY') - to_date('25-04-2012', 'DD-MM-YYYY') + 1;
Here, I need to exclude Dates that lights up "Saturday" and "Sunday" and also the joint birthday partyDT DT 04/25/2012 04/26/2012 04/27/2012 04/28/2012 04/29/2012 04/30/2012 05/01/2012 05/02/2012 05/03/2012 05/04/2012 05/05/2012
Here it is May 1, 2012 "and I need the output as follows,
I need the current request to calculate between two dates.04/25/2012 04/26/2012 04/27/2012 04/30/2012 05/02/2012 05/03/2012 05/04/2012
Can anyone suggest me?
Thank you
Regsrds,
gurujothiselect dt from( select to_date('25-04-2012', 'DD-MM-YYYY') + rownum -1 dt from dual connect by level <= to_date('05-05-2012', 'DD-MM-YYYY') - to_date('25-04-2012', 'DD-MM-YYYY') + 1 ) where to_char(dt,'fmday') not in ('sunday','saturday')
To exclude, common holiday, you must have a host table. Then use an OUTER JOIN NOT IN or NOT EXISTS
-
Find the difference between two date and time
Hi friends,
I wanted to find the difference between two date and time, but my qury is slightest error "invalid number."
select sql_step_num,proc_name,run_seqno,start_date,end_date,(to_char(start_date,'HH24-MI-SS') - to_char(end_date,'HH24-MI-SS') ) as ed from eval.EVAL_RUNTIME_DETAILS where trunc(start_date) = trunc(sysdate) order by sql_step_num;
You try to get the feel between two char strings.
And more difference between two dates gives a NUMBER of days.
Try this:select sql_step_num,proc_name,run_seqno,start_date,end_date,numtodsinterval(end_date-start_date,'DAY') as ed from eval.EVAL_RUNTIME_DETAILS where trunc(start_date) = trunc(sysdate) order by sql_step_num;
-
Dynamic calculation of the number of days between two dates in a table
Hello
I'm working on request where I dynamically calculate the number of days between two dates in a table.
The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.
APEX version: 5.0
Hi BO123,
BO123 wrote:
Hello
I'm working on request where I dynamically calculate the number of days between two dates in a table.
The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.
APEX version: 5.0
one of the way to do this by calling ajax on change of end_date.
See the sample code given below to fetch the resulting duration and making the field read only after calculation
Step 1: Change your page
under CSS-> Inline, put the code below
.row_item_disabled { cursor: default; opacity: 0.5; filter: alpha(opacity=50); pointer-events: none; }
Step 2: Create on demand Ajax process I say CALC_DURATION
Please check Procces Ajax, see line 6.7 How to assign a value to the variable sent by ajax call
Declare p_start_date date; p_end_date date; p_duration number; Begin p_start_date := to_date(apex_application.g_x01); p_end_date := to_date(apex_application.g_x02); --do your calculation and assign the output to the variable p_duration select p_end_date - p_start_date into p_duration from dual; -- return calculated duration sys.htp.p(p_duration); End;
Step 3: Create the javascript function
Change your page-> the function and the declaration of the Global Variable-> put the javascript function
You must extract the rowid in the first place, for which you want to set the time, see line 2
assuming f06, f07 and f08 is the id of the start date, and end date columns respectively, and duration
See no line no 8 how set the value returned by the process of ajax at the duration column
Replace your column to the respective column identifiers in the code below
function f_calulate_duration(pThis) { var row_id = pThis.id.substr(4); var start_date = $('#f06_'+row_id).val(); apex.server.process ( "CALC_DURATION", { x01: start_date,x02: $(pThis).val() }, { success: function( pData ) { // set duration to duration column $('#f08_'+row_id).val(pData); // disable duration column $("#f08_" + row_id).attr("readonly", true).addClass('row_item_disabled'); } }); }
Step 4: choose the end date call the javascript function
Go to report attributes-> edit your Date column end-> column-> Attrbiutes element attributes-> put the code below
onchange="javascript:f_calulate_duration(this);"
hope this helps you,
Kind regards
Jitendra
-
Length of the different interval between two dates in SQL/PLSQL
Dear gurus, here are three questions to ask:
1. Why is the result queries are different?
2 - is a way to measure the length of the interval in seconds (L) between two dates?
2. why the different result is generated in SQL and PL/SQL only to subtract dates from the 28th day of the month?
declare
number of l_offset;
Start
l_offset: = (to_date('09-nov-2009') - to_date ('28.10.2009 10:40:03 ', ' dd.mm.yyyy hh24:mi:ss')) * 86400;))
dbms_output.put_line (l_offset);
l_offset: = (to_date('09-nov-2009') - to_date ('27.10.2009 10:40:03 ', ' dd.mm.yyyy hh24:mi:ss')) * 86400;))
dbms_output.put_line (l_offset);
end;
998396.9999999999999999999999999999999997
1084797
Select (to_date('09-nov-2009') - to_date ('28.10.2009 10:40:03 ', ' dd.mm.yyyy hh24:mi:ss')) * double 86400))
Union of all the
Select (to_date('09-nov-2009') - to_date ('27.10.2009 10:40:03 ', ' dd.mm.yyyy hh24:mi:ss')) * double 86400))
(TO_DATE('09-NOV-2009')-TO_DAT
998397
1084797
Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
PL/SQL Release 9.2.0.7.0 - Production
CORE 9.2.0.7.0 Production
AMT for Linux: release 9.2.0.7.0 - Production
NLSRTL Version 9.2.0.7.0 - ProductionHello
Sorry, I'm still not sure you understand the question.
You wonder why the rounding error is apparent to 6 digits to the left of the decimal separator in numbers, but not in number 7 digits to the left of the decomal? The answer is itself a rounding error.
When Oracle is the arithmetic mean of the dates, the result is a fraction that cannot be stored in a binary number, such as preciesly
998396.9999999999999999999999999999999996857... it it rounds to the nearest value it can store, such as
998396.9999999999999999999999999999999997. in other words, it can store 40 digits. In this case, 6 figures to the left of the decimal separator and 34 of the figures to the right. The number is rounded to the nearest multiple of 10 ^-34 ^
What happens if we add 86400 this number?998396.9999999999999999999999999999999997 + 86400.0000000000000000000000000000000000 ------------------------------------------ 1084796.9999999999999999999999999999999997
Now we need 7 digits before the comma, then round the number to the nearest multiple of 10 ^-33 ^, which is
1084797.000000000000000000000000000000000 -
MaxL Script to clear the data between two dates
Hi all
I need advice to clear the data between two dates, I have three dimensions in my sketch, 'eno', 'hiredate' and the 'actualamount '.
Now I need to erase the data between the date range, up to now, I have this script,
Fix ("HireDate", "Eno")
Difficulty (@relative ("00:00:00",0),@relative("eno",0)) 2015-07-15 "))
CLEARDATA "sal."
endfix
ENDFIX
These scripts only clears on a specific day, but I tried to write the script to clear between two dates, I surfed on a few sites, but no clear answers, finaanly came here, kindly help in this regard.
Thanks in advance.
Have you not tried the format of "startdate":"enddate" for example "August":"September."
See you soon
John
-
Calculate the hours between two dates
Hello
I have a requirement to count the hours with 2 given timestamps, something like:
However, I wish it would be that simple. I just need to count the hours between two timestamps for the hours of work for example, 08:00 - 17:00, MONDAY to Friday (excluding weekends).SQL> select ((to_date('22-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss') - to_date('20-oct-2012 13:00:00','dd-mon-yyyy hh24:mi:ss'))*24) B from dual ; B ---------- 48
So lets say I have to count the hours between two dates above the result should be 18 hours not 48 (4 hours on 20/oct, 9 hours on 21/oct to 5 hours 22/oct).
How can I achieve this? Any idea will be useful.
Thank youMy query generates a list of all the hours between the start and end time, filters on the hours that are outside of the hours of work and then account for the remaining lines. Change that to partial hours must just be a case of replace the two occurrences of 1/24 with 24/01/60, then - as say you - Division COUNT (*) by 60.
There may be performance issues using techniques of generation of line like this, if you put this in a query involving the joining of several lines of other tables (for example where the dates of beginning and end are derived from several employees?) or in several days. If you don't find it then count the number of whole days (taking weekends into account) between dates and work on the partial days after that it could be better. This would probably involve a lot of statements of case (which I don't have time to test it now).
Ben
-
Display the months between two dates
Hello:
I need all the months between two dates. I entered two dates as January 15, 2001 and 2011-mar-03. I want the result as below.
JANUARY 15, 2011 - JANUARY 31, 2011
February 1, 2011 - February 28, 2011
MARCH 1, 2011 - MARCH 3, 2011
I held this result of sql query in oracle. Could you please suggest me?
Thanks in advance.
AbhishekSELECT GREATEST(st, ADD_MONTHS(TRUNC(st, 'MONTH'), (LEVEL - 1))) dt, LEAST(ed, LAST_DAY(ADD_MONTHS(TRUNC(st, 'MONTH'), (LEVEL - 1)))) ld FROM (SELECT DATE '2011-01-15' AS st, DATE '2011-03-03' AS ed FROM DUAL) CONNECT BY LEVEL <= MONTHS_BETWEEN(TRUNC(ed, 'MONTH'), TRUNC(st, 'MONTH')) + 1 ORDER BY 1; DT LD ------------------------ ------------------------ 15.01.2011 00:00:00 31.01.2011 00:00:00 01.02.2011 00:00:00 28.02.2011 00:00:00 01.03.2011 00:00:00 03.03.2011 00:00:00
HTH, Urs
-
How to find the difference between two dates in the presentation layer
Hi gurus,
Hello to everyone. Today, I came with the new requirement.
I need to know the difference between a date and the current date in the formula column application presentation layer.by.
Thank you and best regards,
PratesHi Navin,
TIMESTAMPDIFF function first determines the timestamp component that corresponds to the specified interval setting. For example, SQL_TSI_DAY corresponds to the day component and SQL_TSI_MONTH corresponds to the component "month".
If you want to display the difference between two dates in days using SQL_TSI_DAY, unlike butterflies SQL_TSI_MONTH and so on...
hope you understand...
Award points and to close the debate, if your question is answered.
See you soon,.
Aravind -
get all the date of end of months between two dates
Hi all, I'll try to find together the date of end of months between two dates.
I have the following data in a table
WITH AS's Data1
(
SELECT To_Date('4/30/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual UNION ALL
SELECT To_Date('5/01/2009','mm/dd/yyyy') dt, "TEST2" lname FROM dual UNION all
SELECT To_Date('5/02/2009','mm/dd/yyyy') dt, "TEST3" lname FROM dual UNION all
SELECT To_Date('5/03/2009','mm/dd/yyyy') dt, "TEST4" lname FROM dual UNION all
SELECT To_Date('5/04/2009','mm/dd/yyyy') dt, "TEST5" lname FROM dual UNION all
SELECT To_Date('5/05/2009','mm/dd/yyyy') dt, "TEST6" lname FROM dual UNION ALL
SELECT To_Date('5/31/2009','mm/dd/yyyy') dt, 'TEST7' lname FROM dual UNION all
SELECT To_Date('6/01/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual
)
I would like to write an application that gives you all the end date for months between two dates
for example, if you give the date 9/1/4 and 5/6/9, the output should be
IF I give you the dates 01/04/09 AND 01/06/09, THEN output should beDT LNAME ------------------- 4/30/2009 TEST
as you can see, I want all the end dates of months between two dates by giving the output.DT LNAME ------------------- 4/30/2009 TEST 5/31/2009 TEST7
If I give you 06/05/09 and 05/06/09, and then does so no output because there is no end of month between these two dates.
Similarly, if I give you 30/04/09 and 30/04/09 then output should be 30/04/09 because it is an end of month date
anyone can help to write a query. Thank you very muchJin
Not sure if you need subquery, analytical functions for this.
According to me, which should solve your purpose.WITH data1 AS ( SELECT To_Date('4/30/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual UNION ALL SELECT To_Date('5/01/2009','mm/dd/yyyy') dt, 'TEST2' lname FROM dual UNION all SELECT To_Date('5/02/2009','mm/dd/yyyy') dt, 'TEST3' lname FROM dual UNION all SELECT To_Date('5/03/2009','mm/dd/yyyy') dt, 'TEST4' lname FROM dual UNION all SELECT To_Date('5/04/2009','mm/dd/yyyy') dt, 'TEST5' lname FROM dual UNION all SELECT To_Date('5/05/2009','mm/dd/yyyy') dt, 'TEST6' lname FROM dual UNION ALL SELECT To_Date('5/31/2009','mm/dd/yyyy') dt, 'TEST7' lname FROM dual UNION all SELECT To_Date('6/01/2009','mm/dd/yyyy') dt, 'TEST' lname FROM dual ) select distinct last_day(dt) dt,lname from data1 where dt between &start_date and &end_date and last_day(dt) <= &end_date
also, i have another request. how would i do this without using the data i provided. lets say, i tell you, give me alll the months end between two dates using dual in the from clause of a query. how would you do this in a query or pl/sql? thanks again
Can be like that
with data1 as( select &start_date+level-1 dt from dual connect by level <= &end_date-&start_date+1) select distinct last_day(dt) from data1 where dt between &start_date and &end_date and last_day(dt) <= &end_date order by last_day(dt)
See you soon!
BobinPublished by: Buga added query for updated the need
-
difference between two dates in the year/month/day in Obiee
Hi gurus,
I know this question have been asked and answered several times but I have a requirement that is a little different, then the previous ones.
I want to calculate the difference between two dates in OBIEE10g in year/month/day format similar to the below SQL output
SQL > select end_date, start_date,
trunc (months_between (end_date, start_date) / 12) years.
months of mod (trunc (months_between (end_date, start_date)), 12).
End_date - add_months (start_date, trunc (months_between (end_date, start_date))) days
t
Thanks in advance
SK
Search for this
"TIMESTAMPDIFF IN THE FORM OF MTHS # YEARS."
or else
To get the current mandate of employees since the date of hiring in the form of # years # mths or # year (s) # month (s)
Concat (concat (cast (TIMESTAMPDIFF (SQL_TSI_Month, "Employee attributes". (((' ' Hiring last Date employee ", CURRENT_DATE) / 12 as char),"Year (s)"), concat (cast (MOD (TIMESTAMPDIFF (SQL_TSI_Month,"Employee attributes". (((((' ' Hiring last Date employee ", CURRENT_DATE), 12) as char), 'Month (s)'))
Concat (concat (CAST (TIMESTAMPDIFF (SQL_TSI_YEAR, "Employee attributes". (((' ' Hiring last Date employee ", CURRENT_DATE) as CHAR),"Year (s)"), concat (cast (MOD (TIMESTAMPDIFF (SQL_TSI_Month,"Employee attributes". (((((' ' Hiring last Date employee ", CURRENT_DATE), 12) as char), 'Mth (s)'))
Maybe you are looking for
-
Satellite M45 - S169 PSM43U: need to connect to a serial & parallel
Hello! I have an old model of Satellite and I need to connect to a machine that has the old fashioned entrences with pins (father and mother) and was told that I need a Replicator (series and parallel). Now, I am very confused because I'm not technic
-
Update security for Windows Vista (KB2079403)
Could someone help me and let me know if I really need to install this update? I don't think I do because in my installed programs it says I've got MSXML 4.0 SP2. I don't want to install updates hurt unnecessarily and get some sort of error. Also do
-
When I click the icon it flashes on then nothing
-
Photosmart D110 prints, but not scan
I have a HP toucsmart 310 and a HP photosmart all-in-one D110 over a wireless network. My PC print function works fine, but I can't get the printer to recognize the 310 is on the network, the printer indicates a laptop that is part of the network, b
-
Error updating service runs is not impossible to install Windows update
Original title: Windows Update Windows Update may not work because the update service is not running. There is no error message for this error number.