calculate the difference between two timestamps
HelloI'm new in PL/SQL and have the following problem. In our application, there are events that insert records into a table with a parameter "processing_date" of type DATE (when they will be processed). For a new type of events, I have to plan the 'processing_date' at 18:00 on the day of insertion, if the event has happened until 18:00 and sysdate if event occurs after 18:00.
In a pseudo-code that will be
IF to_char(SYSDATE,'HH24:MI:SS') > 17:59 min 59 s ' THEN - the event took place after 18:00
processind_date: = sysdate;
Else - the event has happened until 18:00
processing_date: = current_timestamp + ('timestamp at 18:00 ' - current_timestamp); -> processing_date: = today at 18:00
END IF;
I'll appreciate any help.
Thank you.
dariusgeo wrote:
processing_date: = current_timestamp + ('timestamp at 18:00 ' - current_timestamp); -> processing_date: = today at 18:00
For 18:00 of the current date, you can do:
processing_date := TRUNC(SYSDATE)+18/24;
TRUNC will be truncates the current date ' 00:00:00 '.
Add 18/24 means add 18 hours (1 day / 24 * 18).
Kind regards.
Al
Published by: Alberto Faenza 22 may 2013 22:07
Tags: Database
Similar Questions
-
How to calculate the difference between two times by the NUMBERS
I'm so bothered by the fact that I can't understand that.
Cell B2 - 08:00
Cell C2 - 10:50
(How can cell D2 - I get this cell to calculate the difference and say 02:50?)
I know it's probably one of the most basic operations, but for the life of me I can't understand it. The cells B2 and C2 are formatted for a 24-hour clock. But if I tell the system to just subtract the two, I get "0,118. Everything I find on the forum search goes beyond what I need. Can someone help me?
Thank you
Hi sapirs,
Departure and arrival of the cells are in Date and time with Date format: no and time: 24-hour clock.
Formula in D2 (fill down)
= C2−B2
The results become a duration format, but under automatic (numbers automatically worth this format)
If you wish, you can change the cells of lasting results.
What Data Format have your result cells?
Kind regards
Ian.
-
How to store the difference between two timestamps as a number?
Hello
I need to find the difference between 2 variables of timestamp and the result will be stored as a number in minutes?
as
declare
timestamp (7) of the fir_timestamp: = 1 January 2012 13:30 ';
timestamp (7) of the sec_timestamp: = 1 January 2012 14:00 ';
c number;
Start
c:=((sec_timestamp-fir_timestamp)/(24*60));
dbms_output.put_line (c);
end;962813 wrote:
declare-fir_timestamp timestamp (7): ='01 - jan - 2012 13:30 ';
timestamp (7) of the sec_timestamp: = 1 January 2012 14:00 '; Incorrect type declarationfir_timestamp timestamp: = 1st January 12 01.30.00.000000 PM';
sec_timestamp timestamp: = 1st January 12 02.00.00.000000 PM';
c number;
Start
c: = ABS ((extrait (HEURE de sec_timestamp) - extract (fir_timestamp TIME)) * 60) +.
ABS ((extrait (MINUTE de sec_timestamp) - extract (fir_timestamp MINUTE)));
dbms_output.put_line (' interval Min Total:-' | c);
end;
/
declare
*
ERROR on line 1:
ORA-01830: date format picture ends before converting all of the input string
ORA-06512: at line 6Follow what Paul has done...
In fact, you do not need timestamp, date data type is enough
SQL> declare 2 fir_timestamp date := 3 to_date('01-jan-2012 13:30:00','dd-mon-yyyy hh24:mi:ss'); 4 sec_timestamp date := 5 to_date('01-jan-2012 14:00:00','dd-mon-yyyy hh24:mi:ss'); 6 c number; 7 begin 8 c:= round((sec_timestamp-fir_timestamp)*24*60); 9 dbms_output.put_line(c); 10 end; 11 / 30 PL/SQL procedure successfully completed.
If you want to place on timestamp
SQL> declare 2 fir_timestamp timestamp := 3 to_timestamp('01-jan-2012 13:30:00','dd-mon-yyyy hh24:mi:ss'); 4 sec_timestamp timestamp := 5 to_timestamp('01-jan-2012 14:00:00','dd-mon-yyyy hh24:mi:ss'); 6 c number; 7 begin 8 c:= round(( 9 to_date(to_char(sec_timestamp,'ddmmyyyyhh24miss'), 10 'ddmmyyyyhh24miss')- 11 to_date(to_char(fir_timestamp,'ddmmyyyyhh24miss'), 12 'ddmmyyyyhh24miss') 13 )*24*60); 14 dbms_output.put_line(c); 15 end; 16 / 30
-
Type of data resulting from the difference between two timestamps
Hi, I have a simple question.
I have two TIMESTAMP A and B variables. Now I want to subtract one B - A. What type of data as a result of this subtraction?
Would Shouln t TIMESTAMP again?
Consider this example:
Thanks for help.DECLARE vdat_Begin TIMESTAMP; vdat_End TIMESTAMP; vdat_Difference TIMESTAMP; BEGIN vdat_Difference := vdat_End - vdat_Begin; -- this doesn't work vdat_Difference := TO_TIMESTAMP(vdat_End - vdat_Begin); -- this works END; / PLS-00382: expression is of wrong type
xxsawer wrote:
Hi, I have a simple question.
I have two TIMESTAMP A and B variables. Now I want to subtract one B - A. What type of data as a result of this subtraction?
Would Shouln t TIMESTAMP again?Consider this example:
DECLARE vdat_Begin TIMESTAMP; vdat_End TIMESTAMP; vdat_Difference TIMESTAMP; BEGIN vdat_Difference := vdat_End - vdat_Begin; -- this doesn't work vdat_Difference := TO_TIMESTAMP(vdat_End - vdat_Begin); -- this works END; / PLS-00382: expression is of wrong type
Thanks for help.
No, as stated, there will be an interval.
-
How to calculate the difference between two numbers in text fields
Hello, I am fairly new to this, and I am certain that I will be bothered by the simple answer is
I do a simple calculation... total of total assets - liabilities = net worth
I have my total assets and my total work of the liability, but is not a subtraction option in the properties of a text field for the Net of a field value.
I don't know... not any script Java can any who help out me?
Thank you
Judy
You can use the option of simplified field notation, but first your input fields names must be changed so that they do not contain spaces or punctuation. For example:
TotalAssets - TotalLiabilities
If you want to use JavaScript, what will be needed if you ever in more complicated calculations, you can use something like the following as the custom fields (net value) calculation script:
(function () {}
Get the values of the field as numbers
var v1 = + getField("total_assets").value;
var v2 = + getField("total_liabilities").value;
calculate the value of this field
Event.Value = v1 - v2;
})();
There are no restrictions on domain names when using JavaScript.
-
difference between two timestamps
Hi gurus,
I have a procedure which has 2 input parameters of type timestamp. I need to find the difference between these two stamps and be converted to a timestamp and return. Help, please
Diifernce between two timestamps is interval. You can not convert the difference between two timestamp timestamp and it makes no sense. What you expect:
25/06/2014 11:25:37.524000 - 13:07:22.987654 20/06/2014
SY.
-
Need help to calculate the difference between times
Hi all
I have two fields that stores just the hour in 24-hour ex: 08:00 and 20:00 now I want to calculate the difference between two times
Kindle help me
Thanks for your help
Thank you
RaviHello
diiference in hours
SQL> WITH T AS (SELECT '08:00' ST_TIME, '20:00' END_TIME FROM DUAL) 2 SELECT (TO_DATE (END_TIME, 'HH24:MI') - TO_DATE (ST_TIME, 'HH24:MI')) * 24 DIFF_HOURS 3 FROM T; DIFF_HOURS ---------- 12 SQL>
G.
-
FormCalc - how to calculate the difference between the two fields datetime in hh: mm?
Hello!
I am building a form of time sheet in which I need to calculate the difference between the start and end times and present the result.
I'm trying to do with FormCalc but if it is easier with JS is ok too.
So that's what I did on the total field, by using the calculate on a NUMERIC field called decimalValue event:
elapsed = Time2Num (endTime.formattedValue, "HH: mm")-Time2Num (startTime.formattedValue, "HH: mm")
And then I tried to convert a time field:
Total = decimalValue.rawValue;
$.formattedValue = Num2Time (total, "HH: mm")
Well, it doesn't work, it gives me crazy results in the datetime (total) field. If I type 09:00 and 09:30, the final result is... 22:30. Huh?
Please, could someone help me understand how this thing works?
Thanks a lot for the tips!
Marcos
Hi Marcos,
Here are some examples:
https://Acrobat.com/#d=kCPIgVkd09qrx6h-WRXxbQ
https://Acrobat.com/#d=EsWqBMBt3sgEXnMSsK5pRA
Hope that helps,
Niall
-
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 -
. For example, I need to calculate the difference between a date column, 'Table_Name '. "' Column_Name ' and (Current_Date-1). I tried different ways to do this. But nothing seems to work.
Try the below formula.
Replace "Time". "" Date "with your column.
TIMESTAMPDIFF (SQL_TSI_DAY, "Time". "Date", TIMESTAMPADD (SQL_TSI_DAY-1, CURRENT_DATE))
Thank you!
-
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
-
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;
-
Calculate the difference between the subtotals
I'm working on a simple report that looks like this:
EmployeeID EmployeeName Date salary wages
1234 Tom June 1, 2009 $2000.00
2345 harry $2400,00 June 1, 2009
3456 sally $3000.00 June 4, 2009
Partial total salary: $7400,00
Advances of salary Date EmployeeID EmployeeName
2345 harry $1000.00 may 15, 2009
3456 sally $750.00 may 15, 2009
Advances subtotal: $1750,00
Total: $5650,00
Is there any function in Discoverer, which calculates the difference between subtotals and the poster as a total. Please advise if you can create a named for this sum calculation?
Published by: user1049091 on August 6, 2009 11:33
Published by: user1049091 on August 6, 2009 12:38Hello
Not really possible. You the best approach is probably to create a named calculation that contains the difference: for example
Decode (salary_type, 'Pay', 'Progress', - wages)
Then create a total on this calculation. You can often hide the calculation itself in terms of formatting and white text on white background.
Rod West
-
Find the difference between two numbers (DBL)
Hi all
Is there a function in labview other than the subtraction function that can find the difference between the two numbers given?
Thank you
Davidson
-
How to calculate the difference between 2 dates, but with interruptions and stops between
Hello
How can I calculate the difference in minutes between 2 dates but taking into account the existence of a table in the Appendix, so if between start_date and end_date arguments, there is no 'work time' then this part of the time will not be included in the total difference.
Records of the time table example:
Time_configuration start_hour end_day end_hour 2 19:00 3 07:00 3 19:00 4 07:00 so for example first record said that on Monday you start at 19:00 and leave the next day at 7:00 and then save the same sort of thing.
There is an event that I want to track how many minutes lasted. for example, this event began the day 2 at 19:00 and ended the day 3 at 21:00
Theoretically, this event really lasted: 840 minutes. This 840 minutes are within the limits of the annex.
Thanks in advance.
The storage of the dates not as data type DATE in most cases is bad design. In addition, how do you know what day of the date is 2 at 19:00? East - Monday 2 November 2015 or Monday, March 7, 2016? It is the same for the event. In any case, assuming that both calendar and events don't extend over several weeks:
According to schedule)
Select time_configuration 2, 19:00 ' start_hour, end_day 3,' 07:00 ' end_hour of all the double union
Select 3, 19:00 ', 4,' 07:00 ' double
),
event like)
Select event_id 1, time_configuration 2, 19:00 ' start_hour, end_day 3: 21:00 ' end_hour of the double
)
Select e.event_id,
Sum)
less (e.end_day + to_date (e.end_hour, 'HH24'), s.end_day + to_date (s.end_hour, 'hh24:mi')).
greater (e.start_day + to_date (e.start_hour, 'HH24'), s.start_day + to_date (s.start_hour,'hh24:mi'))))
) * 24 * 60 minutes
Appendix s,
e event
where e.start_day + to_date(e.start_hour,'hh24:mi')< s.end_day="" +="">
and e.end_day + to_date(e.end_hour,'hh24:mi') > s.start_day + to_date(s.start_hour,'hh24:mi')
E.event_id group
/EVENT_ID MINUTES
---------- ----------
1 840SQL >
SY.
Maybe you are looking for
-
For Mozilla, if you hold a draw? At this time I played on the internet on my browser to mozilla for laptop and then there's also a tab appears and indicates the draw of mozilla container"http://xpdzz.wincentral.yardbrain.kim/?sov=990868299 & hid = cg
-
HP Pavilion 14 use of the N-202AX games
Is HP Pavilion 14 N-202AX for the games? Why does the exhaust part heat when I play games? Thank you
-
Add images to the Manager of the screens.
Hello My screen is a screen, and I have a title and a status of the screen. I want to put the image to fit the middle section of the Manager. I don't need to know how to scale an image I know how to do this. All I need is how to central section width
-
Someone can tell me, is this discharge indicating a problem with the audio driver, or "ks.sys" pointing the cause elsewhere? ********************************************************************************************************** MEMORY_MANAGEMENT
-
Panel of correction lens in Czech Republic
I have on my desktop PC (Windows7 64 bit prof), Photoshop CS6 and Photoshop CC 2015 and on my laptop (Windows7 32 bit prof) only Photoshop CS6. On both computers in Camera Raw in correction lens Panel Nikkor 28-300 f/3, 5-5, 6 ED VR and 16-35 mm f/4