Difference between two dates
Hello
I have two columns both of them date data types.
I would like to know the difference between these two dates.
SELECTION INTERVAL ' + 2342 23:23:23 ' DAY (4) TO THE SECOND - INTERVAL ' + 102 13:13:13 ' DAY (4) SECOND FROM DUAL;
But, I get this:
'+ 2240 10:10:10.000000'
I'd like to see the result in a year-month and jour-deuxieme groups. I can't do anything with + 2240 days...
Thanks in advance!
Hello Adme12
You can use it.
SET LINESIZE 110 PAGESIZE 20
COLUMN today FORMAT A20
COLUMN TOMORROW FORMAT A20
COLUMN YEAR_MONTHS FORMAT A15
COLUMN DAY_SEC FORMAT A30
SET ECHO ON
SELECT TO_CHAR (today, ' JJ.) MR. HH24:MI:SS' YYYY) LIKE TODAY
, TO_CHAR (tomorrow, ' JJ.) MR. HH24:MI:SS' YYYY) TOMORROW
NUMTOYMINTERVAL (MONTHS_BETWEEN (TOMORROW, TODAY), 'MONTHS') AS YEAR_MONTHS
, NUMTODSINTERVAL (TOMORROW - ADD_MONTHS (TODAY, TRUNC (MONTHS_BETWEEN (TOMORROW, TODAY))), 'DAY') AS DAY_SEC
Of
(SELECT SYSDATE + INTERVAL ' + 102 13:13:13 ' DAY (4) ON THE SECOND THAT TODAY ' HUI)
, SYSDATE + INTERVAL ' + 2342 23:23:23 ' DAY (4) ON THE SECOND TOMORROW
OF THE DOUBLE
)
;
TODAY TOMORROW YEAR_MONTHS DAY_SEC
-------------------- -------------------- --------------- ------------------------------
23.04.2014 04:49 10.06.2020 14:59:10 + 000000006-02 + 000000018 10:10:10.000000000
Of course, it is not so good that you have so many 0, but you can convert the result to a char (TO_CHAR) and you can enter.
I hope this helps you!
Kind regards
David
Tags: Database
Similar Questions
-
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)'))
-
How do the time difference between two dates?
Hi all
I use this query to get the time difference between two dates.
Select to_timestamp ('2012-10-03 12:00 ',' YYYY-MM-DD hh)-to_timestamp ('2012-10-03 11:00 ',' YYYY-MM-DD hh) as double diff;
but do not get the correct result.
Thank youLeft KEY... Left Padding of tanks.
-
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 -
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;
-
Difference between two data aquistion
Hello
I got a data aquistion system that is supposed to keep data acquisition selection until the difference between two points a lot. For example, I get voltage (mv) as 2.31, 2.32, 2.34. 2.33 2.32, 2.33 2.32. the data up to a point, say 0.1V higher or lower than the first. Thewhole procss stop. Thank you for your suggestions.
Try this... (Labview 8.2)
-
Dynamic action - Get the difference between two dates + times
I have problems a little dynamic to work action. I'm trying to get the time between two dates with the time difference.
Here is what I got (this is apex 4.0):
Two date pickers + two numbers fields (date/start/end times)
I created a dynamic action on the page who fires on the point lose focus (above points).
The real action for the DA is the body of the PL/SQL function:
When I change the values on the page, I get the following error:declare end_date DATE; start_date DATE; Begin start_date := to_char(:P1_START_DATE || ' ' || :P1_START_TIME, 'DD-MON-YYYY HH:MIAM'); end_date := to_char(:P1_END_DATE || ' ' || :P1_END_TIME, 'DD-MON-YYYY HH:MIAM'); :P1_HOURS := end_date-start_date; End;
AJAX call back Server error ORA-06502: PL/SQL: digital or value error: character number conversion error to set the value.
I'm guessing that there is a problem with the date formatting, but I can't make it work. Thanks in advance!Hi djston,
because you chose the dynamic action of 'Set value' with the "Body of the PL/SQL function" type you need to return the value. Try the following code
declare end_date DATE; start_date DATE; Begin start_date := to_date(:P1_START_DATE || ' ' || :P1_START_TIME, 'DD-MM-YYYY HH:MIAM'); end_date := to_date(:P1_END_DATE || ' ' || :P1_END_TIME, 'DD-MM-YYYY HH:MIAM'); RETURN (end_date-start_date)*24; End;
and P1_REQUESTED_HOURS like 'item affected. "
Concerning
Patrick
-----------
My Blog: http://www.inside-oracle-apex.com
APEX 4.0 Plug-Ins: http://apex.oracle.com/plugins
Twitter: http://www.twitter.com/patrickwolfPublished by: Patrick Wolf on January 17, 2011 10:54
-
How to tell the difference between two dates
Hello:
I have a question on how to get the difference in quantities for two dates in the replies and dashboard.
This is the scenario. I have two guests date and three columns. The first column must be the sum of the amounts for the first quick date. The second column should be the sum of the amounts for the second fast date. And the third column is the difference between the first two columns.
Basically, I'm trying to do something similar to a function of sum of two lines but trying to get the difference between the two rows. Any help to solve this problem would be appreciated.Use the COLUMN FILTERS level...
the first column with the first variable of date quick presentation of the filter
Similarly, the second column in the second variable of quick overview of date filter
Kind regards
Rambeau -
How to find the difference between two dates in time except Sunday
Hi all
I have a table, as shown below.
I would like to know the difference between same tr_ids create_time, which should give out in hours except Sunday.SQL> select * from test; TR_ID CREATE_TIME CODE -------------------------------------------------- --------------------------------------------------------------------------- ---------- S12341 05-JUN-12 12.20.52.403000 AM 1003 S12342 11-JUN-12 11.15.33.182000 AM 1003 S12342 07-JUN-12 12.00.36.573000 PM 1002 S12343 20-JUN-12 12.34.37.102000 AM 1003 S12343 15-JUN-12 11.34.27.141000 PM 1002 S12344 01-JUL-12 10.01.06.657000 PM 1002 S12344 06-JUL-12 12.01.04.188000 AM 1003 S12341 31-MAY-12 11.20.38.529000 PM 1002
For example:
TR_ID: S12344
1002_Create_time: July 1, 12 PM 10.01.06.657000 (i.e. Sunday)
1003_Create_time: 12.01.04.188000 AM 6 July 12
1002 create time is 22:00 Sunday.
If the query must exclude only the hours of Sunday which is 10 p.m. to Monday 00 h which is 2 Hrs.
I tried the sub query after doing a search on this forum but I am not getting the desired output.
Need help to get the desired o/pSELECT count(*) FROM (SELECT ROWNUM RNUM,tr_id,create_time CT_1002 FROM test c WHERE c.tr_id='S12344' and ROWNUM <= (select (cast(a.create_time as date)-cast((select create_time from test b where a.tr_id=b.tr_id and code=1002) as date)) from test a where a.code=1003 and a.tr_id=c.tr_id) + 1) d WHERE to_char(cast((select create_time from test e where e.tr_id=d.tr_id and code=1002) as date) + RNUM - 1, 'DY') NOT IN('SUN');
Hello
If I unederstand the problem correctly, that's what you want:
WITH got_extrema AS ( SELECT tr_id , CAST (MIN (create_time) AS DATE) AS start_date , CAST (MAX (create_time) AS DATE) AS end_date FROM test GROUP BY tr_id ) SELECT tr_id , start_date, end_date -- If wanted , 24 * ( ( ( TRUNC (end_date, 'IW') -- Count -1 day for every full week - TRUNC (start_date, 'IW') ) / -7 ) + LEAST ( end_date -- If end_date is a Sunday , TRUNC (end_date, 'IW') + 6 -- consider it 00:00:00 on Sunday ) - CASE WHEN start_date >= TRUNC (start_date, 'IW') + 6 -- If start_date is a Sunday THEN TRUNC (start_date, 'IW') + 6 -- consider it 00:00:00 Sunday ELSE start_date END ) AS total_hours FROM got_extrema ;
I guess that you don't need to worry about fractions of a second. As you did in the code you have posted, I am to convert the TIMESTAMP to date values, because of DATE arithmetic and functions are so much better than what is available for timestamps.
Basically, it's just to find the number of days between start_date and end_date and multiplying by 24, with these twists:
(a) 1 day is deducted for each week between start_date and end_date
(b) if End_date is a Sunday, none of the end_date himself hours are counted
(c) If start_date is a Sunday, then all the start_date himself hours are counted. Why these hours should be counted? Because 1 day is already being deducted for the week which includes start_date, which contains only this Sunday.TRUNC (dt, 'IW') is the beginning of the ISO week containing dt; in other words, 00:00:00 the or before the dt last Monday. This is not the NLS parameters.
Of course, I can't test without some sample data and the exact results you want from these data. You may need a little something more If start_date and end_date are both on the same Sunday.
Whenever you have a problem, please post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) of all of the tables involved.
Also post the results you want from this data, as well as an explanation of how you get these results from these data, with specific examples.
Always tell what version of Oracle you are using.
See the FAQ forum {message identifier: = 9360002} -
Difference between two dates in the server behaviors
Hello all,.
I am trying to create a Recordset by using server behaviors and that I'm not an expert in php, I'm completely lost...
The problem is this: I want to find in a table of all the records where the difference between today's date and date of creation (stored in this table, although course) is superior to, say 30 days. How can I specify the variable field?
Thank you very much in advance for your help!
You must use a sql like query below:
SELECT * FROM table WHERE creationDate< date_sub(now(),="" interval="" 30="">
'table' is the name of the table that you want to select the information of and 'creationDate' being the column 'date' in the database
-
Difference between two date columns
Dear professionals,
How to get different between two columsn (sati_do-sati_od) in format HH24:
where this results in:select to_char(sati_od,'hh24:mi') "hh:mi format", to_char(sati_do,'hh24:mi') "orginal_value_col2", sati_od "original_value_col1", sati_do "original value", sati_do-sati_od "Difference" from accbtp_pliskljucenjaodobrenja where idplisklj= 22999;
THX in advance, Adnanhh:mi format orginal_value_col2 original_value_col1 original value Difference ------------ ------------------ ------------------------- ------------------------- ---------------------- 09:00 15:00 01.12.10 01.12.10 0,25 09:00 15:00 01.12.10 01.12.10 0,25 09:00 15:00 01.12.10 01.12.10 0,25 09:00 15:00 01.12.10 01.12.10 0,25
select trunc( mod( (e-j)*24, 24 ) ) ||':'||trunc( mod( (e-j)*24*60, 60 ) ) "Hr:Mi" from ( select t.*, trunc(sysdate,'y')+jd+jh/24+jm/24/60 j, trunc(sysdate,'y')+ed+eh/24+em/24/60 e from t ) t
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:96012348060
-
JavaScript anomaly on the number of days between two dates
Use ApEx 4.0, I found an anomaly in a javascript code that calculates the number of days between two dates, the current_date and the past_date. If the past and present is the or before March 10, 2013, and the current_date lies between 10 March 2013 and November 3, 2013, the number of days will be from 1 day to less than the actual number. Between November 3, 2013 and on 4 November 2013, the increments of number by 2, then the count will be accurate from this date forward.
Here are some examples:
March 10, 2013 = 69 days of December 31, 2012
March 11, 2013 = 69 days of December 31, 2012
March 12, 2013 = 70 days of December 31, 2012
November 3, 2013 = 306 days in December 31, 2012
November 4, 2013 = 308 days in December 31, 2012
11 March should be 70 and 12 March should be 71. November 3 is 307 and 4 November corrects the number of fake, which began March 11.
Change the past_date to March 10, 2013 produces the following:
March 10, 2013 = 0 days of March 10, 2013
March 11, 2013 = 0 days of March 10, 2013
March 12, 2013 = 1 days of March 10, 2013
But change the past_date to 11 March 2013, product of the correct numbers:
March 11, 2013 = 0 days of March 11, 2013
March 12, 2013 = 1 days of March 11, 2013
March 13, 2013 = 2 days of March 11, 2013
I would certainly all help to determine the cause of this anomaly. Here's the javascript code:
var w1 = ($v ("P48_PAST_DATE"));
W1 = (w1.toString ());
vmon var = (w1.substr (3.3));
vyr var = (w1.substr (7));
var r = (vyr.length);
If (r == 2)
vyr. = (parseFloat (vyr) + 2000);
vday var = (w1.substr (0.2));
var y = (vmon.concat ("", vday, ",", vyr));
y = Date.parse (y);
var w2 = ($v ("P48_CURRENT_DATE"));
var vmon2 = (w2.substr (3.3));
var vyr2 = (w2.substr (7));
var vday2 = (w2.substr (0.2));
var x = (vmon2.concat ("", vday2, ",", vyr2));
x = Date.parse (x);
var numdays = (x - y);
numdays = (Math.floor(numdays / 86400000));
$s ("P48_NUMBEROFDAYS", numdays);Did you google for something like "javascript number of days between two dates. I think you will find the explanation to this observation:
This method does not work correctly if there is an advanced economies jump between the two dates.
There are examples available to calculate the difference between two dates.
-
Hello experts,
is it possible to get 'normal' date format then tell you the difference between two dates?
For example, I first_unit_start_date (2012.02.17 13:57) and a last_unit_completion_date (2012.02.20 07:23). is it possible to get the calculation answer 17:26?
Now, I found the only way to get minutes with calculation ROUND (1440 * (last date start date and end-first unit), 2)
ThanxHello
You may be able to do by creating a date where the time part holds the difference. Something like:
To_char (trunc (sysdate) + (last_unit_start_date - first_unit_start_date), "HH24")
Rod West
-
Difference of two dates in the month
I need to find the difference between two dates as the number of months:
find the last day of the month of the two dates. subtract and give the difference in number of months.user637544 wrote:
I need to find the difference between two dates as the number of months:
find the last day of the month of the two dates. subtract and give the difference in number of months.Why not just use MONTHS_BETWEEN function? That does not help?
SQL> SELECT sysdate FROM Dual; SYSDATE --------- 01-JUN-09 SQL> SELECT MONTHS_BETWEEN (SYSDATE, 2 TO_DATE ('01/01/2009', 'DD/MM/YYYY') 3 ) diff_in_months 4 FROM DUAL; DIFF_IN_MONTHS -------------- 5 SQL>
You can also use the LAST_DAY function to get the last day of the month.
SQL> SELECT LAST_DAY(sysdate) FROM Dual; LAST_DAY( --------- 30-JUN-09 SQL> SELECT MONTHS_BETWEEN (LAST_DAY(SYSDATE), 2 LAST_DAY(TO_DATE ('01/01/2009', 'DD/MM/YYYY')) 3 ) diff_in_months 4 FROM DUAL; DIFF_IN_MONTHS -------------- 5 SQL>
Kind regards
JOPublished by: Joice John - added LAST_DAY function example
-
find the difference in days between two dates
Hello world
I'm trying to find out the difference in days between two dates and the execution of the query that I'm passing
SELECT TO_char(sysdate, 'dd/mm/yyyy') - TO_char('15/11/2011', 'dd/mm/yyyy') DAYS FROM DUAL
the error I get is
ORA-01722: invalid number
01722 00000 - "invalid number."
* Cause:
* Action:
Could someone please help.
Thanks in advanceuser10636796 wrote:
Hello worldThanks a lot for all the replies. I am trying to apply it in a statement to my table like this
SELECT trunc (sysdate) - TO_char (date_last_recommended, ' dd/mm/yyyy') DAYS OF recommendation;
SELECT trunc (sysdate) - TRUNC (date_last_recommended) DAYS OF recommendation;
Maybe you are looking for
-
Desktop all-in-one HP 19-2113w: product for Windows 8 activation key...
Greetings. I need an activation key for Windows 8 (not 8.1) on my HP 19-2113w all-in-one desktop PC. It came with 8.1 pre-installed, but I need 8 for a new job, I'm starting. I have a valid copy of Windows 8 is installed, I just need the key... I tri
-
How to convert the binary value to a binary string in labview?
Hi all I need to convert the binary value to a binary string. We have decimal or hexadecimal or octal number to decimal string, hexadecimal and octal string
-
Why can't find info on the dt3000i of HP Desktop Hard Drive on your site?
-
How can I find the battery edge in my compag presario Desktop 6000?
I'm trying to locate the edge battery in my compag presario Desktop 6000 so I can replace it
-
How to set up speakers with Toshiba Dynadock U Docking Station
Speaker Toshiba dynadock U Docking Station plug I tried to figure out how to get my speakers to work through the Dynadock U, but have not thought about it. Any advice out there? I use Boston Acoustics with a subwoofer.