get the difference in seconds to a time warp
I need to find a way faster than:(
To_date (to_char (TO_NUMBER (utc_date_new)), 'YYYYMMDDHH24MISS')-
To_date (to_char (TO_NUMBER (utc_date_old)), 'YYYYMMDDHH24MISS')
) * 1440
Thanks... ;(
Hello
Rusty75 wrote:
Sorry, and Yes, his minutes (under a strain here)column has been defined as TIME_UTC VARCHAR2(14 BYTE) NOT NULL
So basically it's a bad situation
How heavy this weighing in a join will select the instruction?
for example, left to join an intermediate table (200,000), with a huge table (40.000.000 rows)
where is equal to staging.varchar indexed field huge varchar field table
AND that calculated the difference > 5?
See [when your query takes too Long | http://forums.oracle.com/forums/message.jspa?messageID=1812597#1812597] for what you must post to get advice on the setting.
Are you saying that the part of the join condition which is the date of a table must be at least 5 minutes later at the time of the other table? In other words, you're doing something like:
FROM staging s
LEFT OUTER JOIN huge_table h ON h.txt = s.txt
AND ( TO_DATE (s.utc_date_new, 'YYYYMMDDHH24MISS')
- TO_DATE (h.utc_date_old, 'YYYYMMDDHH24MISS')
) * 1440 > 5
If so, try to change the terms of join like this:
FROM staging s
LEFT OUTER JOIN huge_table h ON h.txt = s.txt
AND h.utc_date_old < s.utc_date_new
AND ( TO_DATE (s.utc_date_new, 'YYYYMMDDHH24MISS')
- TO_DATE (h.utc_date_old, 'YYYYMMDDHH24MISS')
) > (5 / 1440)
Even if the new condition (the other,
AND h.utc_date_old < s.utc_date_new
are covered by the third condition, it can leave a lot of matches be excluded without a conversion from VARCHAR2 to this DAY.
Also, don't multiply each difference in 1440; Just compare the difference within days to a constant. I don't know if the optimizer is smart enough to do it for you, but why take the risk?
would be to limit the calculation to: to_date (to_number (nw.time_utc), \'YYYYMMDDHH24MISS\')
give a significant increase in speed?
I think it's the opposite. The first TO_DATE argument must be a string; the above expression is to convert the string to a NUMBER (which takes a while), and while the NUMBER is implicitly converted to a VARCHAR2 (which takes more time).
Tags: Database
Similar Questions
-
Get the difference in days between 2 dates in Essbase 9.3.1
How to calculate to get the difference in days between 2 dates in the format day of Essbase 9.3.1.la is 20090101 (yyyymmdd). If 2010907-20100917 = 10 days.
Start and end dates may extend over several years.@DateDiff does not exist in the 9.3.1 I think. With this assumption...
Could you use the CDF 'Functions of Date'? According to the docs (I've never used it):
@JdaysOffset - returns the number of days between the firstDate and the secondDate.See samplecode.oracle.com for the CDF. Just search for CDF and you will find it on the second page (I think) of the FMCS.
Or see this thread for another approach that I think the CDF under the covers: Re: Formate Date.
Of course, you could spend to 11 for DateDiff. :)
Kind regards
Cameron Lackpour
-
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;
-
I can't use the link 'Check the seats' on the website of Delta Airlines when I use Firefox, but Safari works fine. I get the message "not available at this time" when you use Firefox, but when I go on Safari it works just fine. I love Firefox but it sucks!
This problem may be caused by corrupted cookies.
Clear the cache and cookies from sites that cause problems.
"Clear the Cache":
- Firefox > Preferences > advanced > network > storage (Cache) offline: 'clear now '.
'Delete Cookies' sites causing problems:
- Firefox > Preferences > privacy > Cookies: "show the Cookies".
-
Query to get the difference between 2 totals of 2 different queries
I wanted to know if it is possible to get the difference between 2 totals of 2 different queries. Let me explain with an example:
1 application ofst - sum (homepass) Select table 1
2th query: select sum (homepass) from table2
Is it possible to display the difference as -
Select sum (homepass) in table 1 - sum (homepass) from table2
I know that the above query would give syntax error, but is there a better way or something to get the above done task from a single query.
Hopefully, my question is clear.
Please get back with the answer to my query.
Concerning
You can always do something like
SELECT a.cnt - b.cnt FROM (SELECT sum(homepass) cnt from table1) a, (SELECT sum(homepass) cnt from table2) b
I'd be somewhat dubious, although on a data model that had two tables with the same name of the column where it really made sense to subtract one amount from each other. This would strongly imply that there should be a single table with an additional column TYPE eventually.
Justin
-
How to get the difference of two dates in months
Dear friends,
I have 4 items on my page.
2 entered message text (value of loan, monthly deduction)
2 are message style fields (start date, end date)
I need to get the difference from above 2 dates in no.. of months. (for example say N)
So with N, loanvalue should be divided and populated as monthly deduction.
I tried this way, but not able to get the difference of dates
{if ("populateMonthlyDeduction". Equals (PageContext.GetParameter (EVENT_PARAM)))}
System.out.println ("enter populateMonthlyDeduction loop1");
String xxDeductionStartDate = vo.getCurrentRow ().getAttribute("DeducStartDt").toString ();
System.out.println ("xxDeductionStartDate is:" + xxDeductionStartDate);
TXN OADBTransaction = am.getOADBTransaction ();
java.sql.Date DeductionSDate = null;
java.sql.Date DeductionEDate = null;
if(xxDeductionStartDate!=null)
{
java.sql.Date startDate = txn.getOANLSServices () .stringToDate (xxDeductionStartDate);
DeductionSDate = startDate;
System.out.println ("DeductionSDate is:" + DeductionSDate);
}
String xxDeductionEndDate = vo.getCurrentRow ().getAttribute("DedEndDt").toString ();
if(xxDeductionEndDate!=null)
{
java.sql.Date endDate = txn.getOANLSServices () .stringToDate (xxDeductionEndDate);
DeductionEDate = endDate;
System.out.println ("DeductionEDate is:" + DeductionEDate);
}
int difInDays = xxDeductionEndDate-xxDeductionStartDate; -Please correct me
How reach it .plz help.
Thank you
Aravinda
I used a custom like this method and calls this method daysBetween PFR.
I got it. Thanks to you all.
public int daysBetween(As Date, Date etDate)
{
return (int) ((etDate.getTime () - stDate.getTime (()) / (1000 * 60 * 60 * 24));
}
If ("populateMonthlyDeduction". Equals (PageContext.GetParameter (EVENT_PARAM)))
{
System.out.println ("enter populateMonthlyDeduction loop1");
String dedStDt = vo.getCurrentRow ().getAttribute("DeducStartDt").toString ();
String dedEndDt = vo.getCurrentRow ().getAttribute("DedEndDt").toString ();
If (! dedStDt.Equals (null) &! dedEndDt.equals (null))
{
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date sdate = new Date();
Date edate = new Date();
String sdate1 = null;
String edate1 = null;
try {}
sdate = dateFormat.parse (dedStDt);
EDATE = dateFormat.parse (dedEndDt);
SimpleDateFormat dateFormat1 = new SimpleDateFormat("dd-MMM-yyyy");
sdate1 = dateFormat1.format (sdate);
edate1 = dateFormat1.format (edate);
int days = daysBetween(sdate, edate);
int diffInMonths = days/30;
System.out.println ("days is:" + days);
System.out.println ("diffInMonths is:" + diffInMonths);
String sTotValueTuitionFees = vom.getCurrentRow ().getAttribute("TotValueTuitionFees").toString ();//pageContext.getParameter("LoanValue").toString();
int iTotValueTuitionFees = Integer.parseInt (sTotValueTuitionFees);
int iMonthlyDeduction = iTotValueTuitionFees/diffInMonths;
String sMonthlyDeduction = String.valueOf (iMonthlyDeduction);
System.out.println ("iMonthlyDeduction is:" + sMonthlyDeduction);
OAMessageStyledTextBean bMonthlyDeduction = (OAMessageStyledTextBean) webBean.findChildRecursive ("MonthlyDeduction");
bMonthlyDeduction.setValue (pageContext, sMonthlyDeduction);
}
catch (ParseException exception) e
{
}
}
}
-
The most elegant way to get the difference between two tables - not least!
Hello
Simplified example of what I'm trying to achieve - I have two tables ORIGINAL and REVISED.
My aim is to compare the two, such as; -
When there is data in the two tables I get the difference between the Budget column, and if there is no difference, so I don't want no lines.
When data exists in the ORIGINAL, but not in review, I want to the inverse of the current value of the Budget column.
Where the data exist in REVISED I want the REVISED value.
I can see how I can do this, see below, but is there a more elegant solution?
Data for the ORIGINAL table
Data for the REVISED tableselect '801040' entity, '2186' expense_type, 234000 budget from dual union all select '801040' entity, '3001' expense_type, 1000 budget from dual union all select '801040' entity, 'P132' expense_type, 34000 budget from dual union all select '801040' entity, 'P135' expense_type, 43000 budget from dual
Desired outputselect '801040' entity, '2186' expense_type, 235000 budget from dual union all select '801040' entity, 'P132' expense_type, 34000 budget from dual union all select '801040' entity, 'P139' expense_type, 56000 budget from dual
ENTITY EXPENSE_TYPE DIFFERENCE
------ ------------ ----------
801040 2186 1000
801040 3001-1000
801040 P135-43000
801040 P139 56000
5 selected lines.
Code current to achieve this, is there a better way?
Thanks a lot for your comments,.select original.entity , original.expense_type , (nvl(revised.budget,0) - original.budget) as difference from original , revised where original.entity = revised.entity(+) and original.expense_type = revised.expense_type(+) and (nvl(revised.budget,0) - original.budget) != 0 union all select revised.entity , revised.expense_type , revised.budget as difference from revised where not exists (select 'x' from original where original.entity = revised.entity and original.expense_type = revised.expense_type) and revised.budget != 0
Robert.
Published by: Robert Angel on January 17, 2012 03:31 to change is not equal to! = - Thanks for the heads upSQL> with original 2 as 3 ( 4 select '801040' entity, '2186' expense_type, 234000 budget 5 from dual 6 union all 7 select '801040' entity, '3001' expense_type, 1000 budget 8 from dual 9 union all 10 select '801040' entity, 'P132' expense_type, 34000 budget 11 from dual 12 union all 13 select '801040' entity, 'P135' expense_type, 43000 budget 14 from dual 15 ) 16 , revised 17 as 18 ( 19 select '801040' entity, '2186' expense_type, 235000 budget 20 from dual 21 union all 22 select '801040' entity, 'P132' expense_type, 34000 budget 23 from dual 24 union all 25 select '801040' entity, 'P139' expense_type, 56000 budget 26 from dual 27 ) 28 select * 29 from ( 30 select nvl(o.entity, r.entity) entity, 31 nvl(o.expense_type, r.expense_type) expense_type, 32 nvl(r.budget,0) - nvl(o.budget,0) budget 33 from original o 34 full join revised r 35 on o.entity = r.entity 36 and o.expense_type = r.expense_type 37 ) 38 where budget <> 0 39 / ENTITY EXPE BUDGET ------ ---- ---------- 801040 2186 1000 801040 P135 -43000 801040 3001 -1000 801040 P139 56000 SQL>
-
Trying to get the 'difference' between the two tracks
What I'm trying to accomplish is the following: I have an audio track of a voice-over with a music bed located underneath. I also itsself Chamber music, without the voiceover. I want only the share of voice. Is it possible that I can "cancel out" the part of the music or get the difference between the two tracks (just the voice part)? It seems that there should be a way to do it, but for the life of me I can't figure out how do it!
Any advice?
There you go...
http://www.libinst.com/audio%20DiffMaker.htm
Unfortunately, the above utility has been abandoned by its author. :-(
It only works on Windows XP, to start...
-RFH
-
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
-
Get the difference of 2 timestamps in days
I have 2 dates that are stored as the timestamps and I need the number of days between these two days.
If I just subtract these 2, I get an interval but I need the exact number of days.
I tried to get rid of the last part when I the difference but it does not work. (for example 12 00:00:00, I tried to get rid of the 00:00:00)
for example, I gave the date when we send an invoice and the date when it is paid, and I need to know if it is paid in time or not.
No idea how I could do this work? The fact that these are the timestamps causes problems for me.
Thanks in advance
If you don't care to fractions of a second:
Cast (ts_end as date) - cast (ts_start as date)
SY.
-
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} -
How to get the difference in dates in days
Hi friends,
How to get the date difference between two dates exactly
date2-date1 days exactly... shouyld rounded to the nearest value of...
and one entire display i mean positive integer
Select round ((sysdate) - to_date (date_start)), date_start days of per_periods_of_service
This gives negative also resultHello
776317 wrote:
Hi friends,How to get the date difference between two dates exactly
date2-date1 days exactly... shouyld rounded to the nearest value of...
Date1 - date2 is the exact number of days is after date2 date1. (It is as accurate as possible, given that the DATEs do not have fractions of a second).
and one entire display i mean positive integer
Select round ((sysdate) - to_date (date_start)), date_start days of per_periods_of_serviceYou want to probably get the exact number of days first, then ROUND this number:
SELECT ROUND (SYSDATE - TO_DATE (date_start, ...)) AS days FROM per_periods_of_service;
Always pass arguments at least 2 to TO_DATE:
(1) the string to be converted, and
(2) a saying string how (1) is formattedThis gives negative also result
Right; If date1 is before date2 then date1 - date2 returns a negative number.
If you want to never get a negative value, use ABS (date2 - date1). If it returns 4, then you know that one of the DATEs was 4 days before the other, but you won't know who was earlier.I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using. -
How to get the difference of current and previous line for a column of the same table?
Hello
I have a table where there are 3 rows and say 2 columns only, as below
Col1 | Col2
--------------------- |----------------------------------------first_flag | 100
second_flag | 104
third_flag | 110
Now, using sql, which accepts a parameter col1, how do I get the bottom o/p
say that the entry is second_flag,
output must be
second_flag, 104, 4 (4 being the difference between 104 and 100)
If I give the entry like third_flag, the output should be
third_flag, 110, 6 (6 is the difference between 110 and 104)
Any help?
Hello
Another way is to use the analytic LAG function:
WITH got_diff AS
(
SELECT col1, col2
, col2 - LAG (col2) over (ORDER BY col1) AS diff
OF mydata
)
SELECT *.
OF got_diff
WHERE col1 =: flag_wanted
;
This assumes that the lines are in alphabetical order by col1. If the order is something else, then use it in the ORDER BY clause analytical.
-
Calculate the difference between AM and PM time
I use a form and I want to have the time between two times calculated. This part works - but I have problems getting the data after that contribution has been calculated.
When you enter a time in the format hh: mm tt - I so that it has calculated and output in the format hh: mm already. He does not accept this entry however - just trying to use everything that is initially formatted. Currently, this is how I capture the data of these two areas, I need to take data. I can take this and people have to use military time, but I'd rather just take input in the format hh: mm tt.
var hrsStart = parseInt(this.getField("sTime").value.split(":")[0]);
var minStart = parseInt(this.getField("sTime").value.split(":")[1]);
var hrsEnd = parseInt(this.getField("stTime").value.split(":")[0]);
var minEnd = parseInt(this.getField("stTime").value.split(":")[1]);
That's how I'm calculation of data entry in the two fields.
var time = this.getField("stTime");
var hours = Number(time.match(/^(\d+)/)[1]);
var minutes = Number(time.match(/:(\d+)/)[1]);
var AMPM = time.match(/\s(.*)$/)[1].toLowerCase();
if (AMPM == "pm" && hours < 12) hours = hours + 12;
if (AMPM == "am" && hours == 12) hours = hours - 12;
var sHours = hours.toString();
var sMinutes = minutes.toString();
if (hours < 10) sHours = "0" + sHours;
if (minutes < 10) sMinutes = "0" + sMinutes;
this.getField("stTime").value = (sHours +':'+sMinutes);
My answer of Validation?
I also tried to make getHours / getMinutes, but values come up unresolved.
I will accept any help - even if it is not consistent with this solution. I agree with being completely wrong. =)
You must add the part of the date as a static string in your code. Something like this:
util. SCAND ("h: mm tt d/m/yy", strStart + "01/01/15");
-
I tried to cancel a download that happened on its second day, the only thing he said to me, it's the application in place has an estimated time of 1 second.
Right click on the taskbar, the Manager select task and, in the 'Applications' tab, select the download and click "end task." (you may need to click on 2 or 3 times if it broke down)
Maybe you are looking for
-
How can I get rid of congratulations you have won in firefox!
Hi guysI have a popup in Firefox that continue to flow upward 'CONGRATULATIONS YOU HAVE WON' now the popup is not an investigation. He skillfully use popup when switching between pages. The funny part is that you can not close the pop-up window. Norm
-
How can I disable Sync? I've never used and and I do not have an account.
Whenever I use FF, I get a dialog box remember the password. How to disable the Sync feature?
-
Dialp cushion keeps appearing...
Hello. I met question button dial. I reinstalled the Mavericks 10.9.4 and installed Skype last. However, I can't disable dialp pad to appear at the start of Skype. Tried to reinstall 5 times, tried to install the old version and update again - did no
-
Where can I get accessorize for Qosmio?
Hi where can I accessorize for qosmio
-
My computer is running slow - someone has already tried the 'CLEAN MY PC' or something like that - do they work? Any other suggestions?