Calcuate Hours: Minutes:Seconds between two dates excluding Weekends
Hello All,
@StartDate = '2014-06-21 13:37:30:037'
@EndDate = GetDate()
I want to find out Hours:Minutes:Seconds between the above dates EXCLUDING WEEKENDS.
Please help.
ReportingServices
Hi,
Give this a try:
DECLARE @StartDate DATETIME = '2014-06-21 13:37:30:037'
DECLARE @EndDate DATETIME = GETDATE()
DECLARE @Base INT = 86400 -- ie Seconds in a days
;WITH cteCalculation AS (
SELECT ((
(DATEDIFF(dd, @StartDate, @EndDate) + 1)
-(DATEDIFF(wk, @StartDate, @EndDate) * 2)
-(CASE WHEN DATENAME(dw, @StartDate) = 'Sunday' THEN 1 ELSE 0 END)
-(CASE WHEN DATENAME(dw, @EndDate) = 'Saturday' THEN 1 ELSE 0 END)
) * @Base)
-(CASE WHEN DATENAME(dw, @StartDate) NOT IN ('Saturday', 'Sunday') THEN DATEPART(hh, @StartDate) * 3600 + DATEPART(mi, @StartDate) * 60 + DATEPART(ss, @StartDate) ELSE 0 END)
-(CASE WHEN DATENAME(dw, @EndDate) NOT IN ('Saturday', 'Sunday') THEN @Base - (DATEPART(hh, @EndDate) * 3600 + DATEPART(mi, @EndDate) * 60 + DATEPART(ss, @EndDate)) ELSE 0 END)
AS DiffInSec
SELECT @StartDate
,@EndDate
,CAST(DiffInSec / 3600 AS VARCHAR(10)) + ':' +
RIGHT('0' + CAST((DiffInSec % 3600) / 60 AS VARCHAR(2)), 2) + ':' +
RIGHT('0' + CAST((DiffInSec % 3600 % 60) AS VARCHAR(2)), 2)
FROM cteCalculation
Feel free to modify to suit your needs!
Hope this helps.
~J.
Similar Messages
-
Calculate the Difference Between two dates excluding weekends and Holidays
Hi,
We need to calculate the difference between the two dates by excluding the Local public holidays (It is global and varies across countries) and weekends should not be included in calculation for a business day in OBIEE.
We have two dates: Open date and close date when ever close date is null we are calculating age based on taking the current timestamp and need to exclude the weekends and Holidays when ever the close date is null.
Ex:
Col1 col2 Total
11/9/2010 2:46:38 PM Null 13
11/2/2010 8:06:26 PM 11/3/2010 5:37:03 PM 1
(In the Total we shouldn't include the weekends,holidays)
Please let me know how to calculate the difference between two dates by excluding the weekends and holidays.
Thanks
Edited by: user10441472 on Nov 22, 2010 3:14 PMYou already asked this question and I answered it...
Re: calculation of Business day in OBIEE -
Adding day/hour/minute/second to a date value
How does one add a day/hour/minute/second to a date value?
SQL> select to_char(sysdate, 'DD/MM/YYYY HH24:MI:SS') to_day,
2 to_char(sysdate+1, 'DD/MM/YYYY HH24:MI:SS') add_day,
3 to_char(sysdate + 1/24, 'DD/MM/YYYY HH24:MI:SS') add_hour,
4 to_char(sysdate + 1/(24*60), 'DD/MM/YYYY HH24:MI:SS') add_minute,
5 to_char(sysdate + 1/(24*60*60), 'DD/MM/YYYY HH24:MI:SS') add_second
6 from dual
7 /
TO_DAY ADD_DAY ADD_HOUR ADD_MINUTE ADD_SECOND
10/10/2006 11:54:23 11/10/2006 11:54:23 10/10/2006 12:54:23 10/10/2006 11:55:23 10/10/2006 11:54:24
SQL>Cheers
Sarma. -
How to Calculate second between two dates?
I'm wish to create a ref ID using seconds between two dates as the uniue number. I usually use DateDiff function in VB to calculate the ref ID. But now instead developing using VB, i'm using java in developing my project. I wonder is there any class similar to the datediff function? Please advice.Thank you
diff_sec =( Date1.getSeconds() - Date2.getSeconds());
-
How to count days between two dates excluding saterady and sunday
Hi all
iam working on oracle sql/plsql.
In my application , i need to caliculate leave days between two dates excluding saterady and sunday
Please tell me the solution if any one knows
thanks in advance ,
baluMore modern version:
WITH date_tab AS
(SELECT TO_DATE ('&from_date', 'dd-MON-yyyy')
+ LEVEL
- 1 business_date
FROM DUAL
CONNECT BY LEVEL <=
TO_DATE ('&to_date', 'dd-MON-yyyy')
- TO_DATE ('&from_date', 'dd-MON-yyyy')
+ 1)
SELECT business_date
FROM date_tab
WHERE TO_CHAR (business_date, 'DY') NOT IN ('SAT', 'SUN');Thank you,
Tony Miller
Webster, TX
Never Surrender Dreams!
JMS
If this question is answered, please mark the thread as closed and assign points where earned.. -
Count days between two dates without weekend
Hi,
I need a solution in query or another thread, that returns the count of days between two dates without consider weekend (saturday and sunday) , I have the columns of type Date, and the return need in format of hours in one column hh:mm:ss and days in another column.
Regards
JonasHi and welcome to the forum.
Keep in mind that you can do a search on this forum.
Your question has been asked before.
Some other pointers:
http://asktom.oracle.com/pls/asktom/ASKTOM.download_file?p_file=6551242712657900129
http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:185012348071 -
Day between two dates excluding Saturday and Sunday
Hi,
I have the Requirement like : there are two inputs in query 1)startdate and 2)end date when end user enter the start date and end date the sql query has to retrive the number of days between given start and end dates, and it should be retrivied with two condition 1)all sundays between the above dates excluded 2)second and fourth Saturday of the month in between the start and end dates has to be excluded .
example start date:01-may-09
end date: 16-may-09
expected output:13Balaji.M wrote:
Hope this will be helpful for you.
SELECT dates,
TO_CHAR(dates, 'D'),
TO_CHAR(dates, 'DAY'),
TO_CHAR(inner.dates, 'W')
FROM (SELECT TO_DATE('01-may-09') + LEVEL - 1 dates
FROM DUAL
CONNECT BY LEVEL <= (TO_DATE('16-may-09') - TO_DATE('01-may-09')) + 1) inner
WHERE ( ( TO_CHAR(inner.dates, 'D') = 7
AND TO_CHAR(inner.dates, 'W') NOT IN(2, 4)
OR TO_CHAR(inner.dates, 'D') not in (1,7)
You can replace the start date (two place) and end date (one place) by variables and check.Of course we have to be aware of local NLS settings:
SQL> SELECT dates,
2 TO_CHAR(dates, 'D'),
3 TO_CHAR(dates, 'DAY'),
4 TO_CHAR(inner.dates, 'W')
5 FROM (SELECT TO_DATE('01-may-09') + LEVEL - 1 dates
6 FROM DUAL
7 CONNECT BY LEVEL <= (TO_DATE('16-may-09') - TO_DATE('01-may-09')) + 1) inner
8 WHERE ( ( TO_CHAR(inner.dates, 'D') = 7
9 AND TO_CHAR(inner.dates, 'W') NOT IN(2, 4)
10 )
11 OR TO_CHAR(inner.dates, 'D') not in (1,7)
12 );
DATES T TO_CHAR(D T
01-MAY-09 5 FRIDAY 1
02-MAY-09 6 SATURDAY 1
03-MAY-09 7 SUNDAY 1
05-MAY-09 2 TUESDAY 1
06-MAY-09 3 WEDNESDAY 1
07-MAY-09 4 THURSDAY 1
08-MAY-09 5 FRIDAY 2
09-MAY-09 6 SATURDAY 2
12-MAY-09 2 TUESDAY 2
13-MAY-09 3 WEDNESDAY 2
14-MAY-09 4 THURSDAY 2
15-MAY-09 5 FRIDAY 3
16-MAY-09 6 SATURDAY 3
13 rows selected.
SQL>Day 1 on my local database is Monday, not Sunday. -
How to get the dates between Two dates excluding Saturaday and Sunday
Dear All,
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;The above query returning the following output,
DT
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/2012here I need to exclude the Dates which comes on 'saturday' and 'sunday' and also the common holiday
Here it is '01-May-2012' and I need the output like the following,
04/25/2012
04/26/2012
04/27/2012
04/30/2012
05/02/2012
05/03/2012
05/04/2012I need the common query to calculate between any two dates.
Can anyone suggest me?
Thank you,
Regsrds,
gurujothiHi Frank,
Sorry for my fault,
The following is my table description,
CREATE TABLE "DATES"
( "FROMDATE" DATE,
"TODATE" DATE,
"LEAVE_ID" Number(5)
Insert into dates values('05-02-2012','05-05-2012',1);
Create table holiday_dates(holidays date);
insert into holiday_dates values('01-05-2012');Now when I used this query,
select count(*) from (select dt
from(
select to_date(fromdate, 'DD-MM-YYYY') + rownum -1 dt
from dates
connect by level <= to_date(todate, 'DD-MM-YYYY') - to_date(fromdate, 'DD-MM-YYYY') + 1
where to_char(dt,'fmday') not in ('sunday','saturday') minus (select holidays from holiday_dates)) dual;
Count(*)
64
Insert into dates values('01/05/2012','05/05/2012',2);
/Now my table has 2 rows,
select * from dates;
FROMDATE TODATE LEAVE_ID
01/05/2012 05/05/2012 1
05/02/2012 05/05/2012 2Now when I used this query,
select count(*) from (select dt
from(
select to_date(fromdate, 'DD-MM-YYYY') + rownum -1 dt
from dates
connect by level <= to_date(todate, 'DD-MM-YYYY') - to_date(fromdate, 'DD-MM-YYYY') + 1
where to_char(dt,'fmday') not in ('sunday','saturday') minus (select holidays from holiday_dates)) dual;The output is ,
COUNT(*)
1987How to get the output using the max(leave_id) like the following,
select..........from... where leave_id=(select max(leave_id) from dates);where to add "WHERE" clause in the above query?
Thank you,
Regards,
Gurujothi.
Edited by: Gurujothi on May 3, 2012 8:43 PM
Edited by: Gurujothi on May 3, 2012 8:44 PM -
How to get difference in days between 2 dates excluding weekends
Hi all,
i have a requirement, to calculate the difference between 2 dates, in days.
eg: 01/08/2007 and 05/08/2007.
Difference = 4 days.
But here my actual requirement is i have to calculate this difference excluding weekends (saturday n sundays).
eg: 01/08/2007 -
Thursday
05/08/2007 -
Monday
so now Difference = 2 days.
Please help me regarding this.
Points will be rewarded for helpfull answers.
Thanks in Advance.
Regards,
Vineelsee these codes of rich
report zrich_0003.
data: begin of itab occurs 0,
datum type sy-datum,
end of itab.
data: weekday like dtresr-weekday.
data: number_lines type i.
parameters: p_sdatum type sy-datum,
p_edatum type sy-datum.
itab-datum = p_sdatum.
append itab.
do.
if itab-datum = p_edatum.
exit.
endif.
itab-datum = itab-datum + 1.
call function 'DATE_TO_DAY'
exporting
date = itab-datum
importing
weekday = weekday.
if weekday = 'Sat.'
or weekday = 'Sunday'.
continue.
endif.
append itab.
enddo.
describe table itab lines number_lines.
write:/ 'Number of days between dates is', number_lines.
and
report zrich_0001.
parameters: p_start type sy-datum,
p_end type sy-datum.
data: idays type table of rke_dat with header line.
data: workingdays type i.
call function 'RKE_SELECT_FACTDAYS_FOR_PERIOD'
exporting
i_datab = p_start
i_datbi = p_end
i_factid = 'P8' " Fact Calender ID
tables
eth_dats = idays
exceptions
date_conversion_error = 1
others = 2.
describe table idays lines workingdays.
write:/ workingdays.
I want to find the No.of working days between the two dates
regards,
srinivas -
Displaying the hour, minute, seconds.....
Hi fellow experts!
Once again I call upon you for help. I'm strugglng with the formatting of dates...specifically the hour, minute, seconds between two dates.
Sample data:
create table test (script_name varchar2(50),run_start date,run_end date, job_id number, parent_job_id number);
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('IMPORTMTM','09-FEB-10','09-FEB-10','2409671','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('INT_EOD_VALUATIONS','09-FEB-10','09-FEB-10','2409673','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('ACC_EOD_FXACCOUNTING','09-FEB-10','09-FEB-10','2409677','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('GLO_EOD_FXUPDATE ','09-FEB-10','09-FEB-10','2409679','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('MX_PREACCOUNTING_BACKUP_RP','09-FEB-10','09-FEB-10','2409683','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('DM_PREACCOUNTING_BACKUP_RP','09-FEB-10','09-FEB-10','2409684','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('IMP_FIXING','09-FEB-10','09-FEB-10','2409688','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('GLO_EOD_FIXINGIRD','09-FEB-10','09-FEB-10','2409690','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('WAIT_5_MINS','09-FEB-10','09-FEB-10','2409692','2409645');
The output of the time should look like the results from the query below:
select floor((run_end-run_start)*24) as Hrs ,floor(((run_end-run_start)*1440 - floor((run_end-run_start)*24)*60)) as Mins,
ceil(((run_end-run_start)*86400 - floor((run_end-run_start)*1440)*60)) as Secs
from (
select to_date('10-oct-2003 15:02:23','DD-Mon-YYYY HH24:Mi:SS') as run_start,
to_date('10-oct-2003 16:20:20','DD-Mon-YYYY HH24:Mi:SS') as run_end
from dual);
i.e
H M S
1 17 57
My current sql is:
select script_name,
run_start,
run_end,
floor((run_end-run_start)*24) as Hrs ,floor(((run_end-run_start)*1440 - floor((run_end-run_start)*24)*60)) as Mins,
ceil(((run_end-run_start)*86400 - floor((run_end-run_start)*1440)*60)) as Secs
from (
select lpad(' ',5*level,' ')||name script_name
,to_date(run_start,'dd-mon-yyyy hh24:mi:ss') run_start, to_date(run_end,'dd-mon-yyyy hh24:mi:ss') run_end,
sys_connect_by_path(to_date(run_start,'dd-mon-yyyy hh24:mi:ss'),'/') root_start
from jcs_jobs
connect by prior job_id = parent_job_id
start with PARENT_JOB_ID IS NULL and job_id = 2409645
I need a slight tweak somewhere, but can't quite get there!
Oracle version is 9i
Many thanks for your help in advance.
DevHi,
Devski Peters wrote:
......sorry, I didn't make myself clear.....Sorry, this message made things even less clear.
Like Bhushan, I don't see any relationship between the data you posted:
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('IMPORTMTM','09-feb-2010 20:00:02','09-feb-2010 20:00:44','2409671','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('INT_EOD_VALUATIONS','09-feb-2010 20:00:44','09-feb-2010 20:01:03','2409673','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('ACC_EOD_FXACCOUNTING','09-feb-2010 20:01:05','09-feb-2010 20:01:24','2409677','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('GLO_EOD_FXUPDATE ','09-feb-2010 20:01:24','09-feb-2010 20:01:43','2409679','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('MX_PREACCOUNTING_BACKUP_RP','09-feb-2010 20:01:45','09-feb-2010 20:01:49','2409683','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('DM_PREACCOUNTING_BACKUP_RP','09-feb-2010 20:01:45','09-feb-2010 20:01:49','2409684','2409645');
insert into test (script_name,run_start,run_end,job_id,parent_job_id) values ('IMP_FIXING','09-feb-2010 20:01:51','09-feb-2010 20:02:15','2409688','2409645');and the results you want:
NORMAL_DAY 09-feb-2010 18:05:00 10-feb-2010 04:22:45 20'681'879.88
Step 1 of NORMAL_DAY 09-feb-2010 18:05:00 09-feb-2010 18:05:24 575.88
Step 2 of NORMAL_DAY 09-feb-2010 18:05:24 09-feb-2010 18:05:46 527.88
EOD_FX_RATE_UPLOAD 09-feb-2010 18:05:24 09-feb-2010 18:05:46 527.88
Step 1 of EOD_FX_RATE_UPLOAD 09-feb-2010 18:05:24 09-feb-2010 18:05:30 143.88
FX_FTPS_GET_EOD 09-feb-2010 18:05:26 09-feb-2010 18:05:30 95.88
Step 2 of EOD_FX_RATE_UPLOAD 09-feb-2010 18:05:30 09-feb-2010 18:05:45 359.88
FXSPOTS 09-feb-2010 18:05:31 09-feb-2010 18:05:45 335.88
Step 3 of EOD_FX_RATE_UPLOAD 09-feb-2010 18:05:45 09-feb-2010 18:05:46 23.88
SEND_MAIL_FXSPOTS 09-feb-2010 18:05:45 09-feb-2010 18:05:46 23.88
Step 3 of NORMAL_DAY 09-feb-2010 18:05:46 09-feb-2010 18:06:10 1'535.88
CALENDAR_UPLOAD 09-feb-2010 18:05:47 09-feb-2010 18:06:10 1'511.88
Step 1 of CALENDAR_UPLOAD 09-feb-2010 18:05:47 09-feb-2010 18:05:53 143.88
CALENDAR 09-feb-2010 18:05:47 09-feb-2010 18:05:53 143.88
Step 2 of CALENDAR_UPLOAD 09-feb-2010 18:05:53 09-feb-2010 18:06:00 1'127.88
MDS_STOP 09-feb-2010 18:05:53 09-feb-2010 18:06:00 1'127.88
Step 3 of CALENDAR_UPLOAD 09-feb-2010 18:06:00 09-feb-2010 18:06:03 71.88
MDS_HOLIDAY 09-feb-2010 18:06:00 09-feb-2010 18:06:03 71.88
Step 4 of CALENDAR_UPLOAD 09-feb-2010 18:06:03 09-feb-2010 18:06:10 167.88Do you really want that data to produce that output?
If the results are not from that data, then post a consistent set of data and results.
When you have poted some sample data and the results you want from that data , explain how you get those results. Pick a couple of rows of output, and explain how you got every column in the results from the data. Be specific.
The table has a 'pig ear' relationship......so job_id can have the same parent_job_id.....What is a "pig ear" relationship? (I like the name.)
>
The connect by allows me display the results with indentation, so the results will look like:The results look completely unformatted on my browser.
When you post any formatted text on this site, type these 6 characters:
(small letters only, inside curly brackets) before and after each formatted section.
So for example,the first line shows a time of 20'681'879.88, which works out to 10:18 hours approx. Explain the relationship between 20'681'879.88 and "10:18 hours". (Do you mean 10 hours plus 18 minutes?) -
Re: difference between two dates
Try this:
diff : integer = IntervalData().Subtract(<DateTimeData1>,<DateTimeData2>).
ConvertToUnit(<resolution>);
<resolution> can be set to DR_SECOND,DR_MILLISECOND,DR_DAY etcetera
Hope it helps,
Steven Arijs
Ed Havelaar, Information Services Section wrote:
Suppose I've got two DateTimeData objects.
How do I find out the difference in days, hours, minutes, seconds
between the two? Is it possible without converting them both to text
strings?
IntervalData only seems to have DifferenceInMonths() and
DifferenceInYears().
- Ed
================================================================================
Eduard E Havelaar, Information Services Section, University of Canterbury
email: [email protected]
phone: +64-3-366 7001 extn 8910
fax: +64-3-364 2999
snailmail: Private Bag 4800, Christchurch, New ZealandHi,
Here the Data Types are TimeStamp.I want to display in the table.I just used the below code.
public long dateCalculation(oracle.jbo.domain.Timestamp fromDate, oracle.jbo.domain.Timestamp toDate){
Long diffInDates = 0L;
try {
java.util.Date date1 = new java.util.Date(fromDate.getTime());
java.util.Date date2 = new java.util.Date(toDate.getTime());
int m1 = date1.getYear() * 12 + date1.getMonth();
int m2 = date2.getYear() * 12 + date2.getMonth();
long diff= m2 - m1 ;
return m1 - m2 ;
} catch (Exception e) {
e.printStackTrace();
i called the above method by using value change listner
i.e
public void PeriodCalculation(ValueChangeEvent valueChangeEvent) {
getPeriod().setValue(""+dateCalculation((oracle.jbo.domain.Timestamp)getPeriodto().getValue(),(oracle.jbo.domain.Timestamp)getPeriodfrom().getValue()));
If anything wrong in my code please let me know
Thanks,
G.Shilpa. -
Removing Weekends in between two dates
Hi,
I need to get the number of days in between two dates excluding the weekends.
Does anyone know how to do this?
Thanks.Here's a search of the forum for "difference dates". At least the first three questions are identical to yours.
http://search.java.sun.com/Search/java?col=javafrm&qp=%2Bforum%3A31&qt=difference+dates&x=12&y=10 -
Difference between two dates in hours
hi
i want to write the procedure which will give me the difference of two dates in hours.
there are two columns start_dt and end_dt and i want to calculate the difference between them in hours.
morever i want to add functionality like if the start or end date falls on weekend(saturday & sunday) i want to subtract that whole period(which obviously will be in hours) from the total hours elapsed between two dates.
could anyone please help me in this?
regards,
PDnicolas..
thanks for bringing this into my notice..
i used ur one of the reply..
select
to_char(sysdate,'dd-mm-yyyy hh:mi:ss') d1,
to_char(sysdate-45.4,'dd-mm-yyyy hh:mi:ss') d2,
trunc(sysdate-(sysdate-45.4)) "Days",
trunc(((sysdate-(sysdate-45.4))-trunc(sysdate-(sysdate-45.4)))*24) "Hours",
trunc(((((sysdate-(sysdate-45.4))-trunc(sysdate-(sysdate-45.4)))*24)-trunc(((sysdate-(sysdate-45.4))-trunc(sysdate-(sysdate
-45.4)))*24))*60) "Minutes",
trunc((((((sysdate-(sysdate-45.4))-trunc(sysdate-(sysdate-45.4)))*24)-trunc(((sysdate-(sysdate-45.4))-trunc(sysdate-(sysdat
e-45.4)))*24))*60)-trunc(((((sysdate-(sysdate-45.4))-trunc(sysdate-(sysdate-45.4)))*24)-trunc(((sysdate-(sysdate-45.4))-tru
nc(sysdate-(sysdate-45.4)))*24))*60)) "Second"
from dual
it's working but the problem is that i also have to give functionality like if the start_dt or end_dt is on holiday(i.e. weekend or holiday) i need to subtract the hours spent during holiday period from total hours.
any help?
regards,
PD!! -
Finding difference of Hours between two dates
I need logic to find the difference of number of hours between any two dates excluding saturdays & sundays. Please provide PLSQL code.
my dear
this is the pl/sql to create on db.
| | This function it will created on the data if you like.
| | the input parameter for this function is two date .
| | you can add more feature on it because turn it felixable eg.
| | you can execlude varaible days from paramteres....
CREATE OR REPLACE FUNCTION GET_HOURS(P_FROM_DATE IN DATE ,
P_TO_DATE IN DATE DEFAULT SYSDATE ,
P_EXECLUDE IN VARCHAR2 DEFAULT '17' ) RETURN NUMBER IS
V_CURR_DATE DATE := P_FROM_DATE ;
V_ALL_DAYS NUMBER := 0 ;
V_NET_HOURS NUMBER := 0 ;
V_FROM_JUL NUMBER := TO_CHAR(P_FROM_DATE,'J');
V_TO_JUL NUMBER := TO_CHAR(P_TO_DATE,'J');
BEGIN
FOR R IN V_FROM_JUL..V_TO_JUL LOOP
IF INSTR(P_EXECLUDE,TO_CHAR(V_CURR_DATE,'D')) = 0 THEN
V_ALL_DAYS := V_ALL_DAYS + 1 ;
END IF;
V_CURR_DATE := V_CURR_DATE+ 1 ;
END LOOP;
V_NET_HOURS := V_ALL_DAYS * 24 ;
RETURN(V_NET_HOURS);
END;
-- this is for test senario
SELECT GET_HOURS(SYSDATE-30) FROM DUAL ;
SELECT GET_HOURS(SYSDATE-30,SYSDATE,'127') FROM DUAL;
SELECT GET_HOURS(SYSDATE-30,SYSDATE,'0') FROM DUAL; -- to execlude zero days. -
How to calculate the hour difference between two dates?
hi all,
how to calculate the hour difference between two dates?
eg i trying this...
((TO_DATE(TO_CHAR(GRNi.reference_date_4,'hh24:mi'),'hh24:mi') -
TO_DATE(TO_CHAR(NVL(GRNi.reference_date_3,SYSDATE),'hh24:mi'),'hh24:mi'))*24)*60 Act_Hr
Reg.
AAKHi
To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following:
select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ),
trunc( sysdate-created ) "Dy",
trunc( mod( (sysdate-created)*24, 24 ) ) "Hr",
trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi",
trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec",
to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ),
sysdate-created "Tdy",
(sysdate-created)*24 "Thr",
(sysdate-created)*24*60 "Tmi",
(sysdate-created)*24*60*60 "Tsec"
from all_users
where rownum < 50
HTH
RangaReddy
Maybe you are looking for
-
Font rendering issue after motherboard upgrade
This is a strange one. Took hard-disc containing 10.6.7 out of a 2006 MacBook and put it in a 2007 MacBook. Everything is working 100%, except for some slight differences in fonts. In some apps, they are rendered thicker (seeming only when shadowed),
-
Why is the formula column returning garbage?
I've set up a query that performs a full outer join on two tables, returning one field from each table. Each of these fields is created by concatenating several other fields from that table, i.e. Select a.field1 || a.field2 fielda, b.field3 || b.fiel
-
More 790GX-G65 Crossfire Questions
I just purchased two used Sapphire ATI HD3850 512MB video cards for a very reasonable price. I understand crossfire won't work with the motherboard's HD3300 IGP. I have some questions: 1. Will I be able to use the video connections through the moth
-
ICloud email address when I have existing Apple ID
I'm sure this has been solved but could not narrow down this scenario in the support community. My current Apple ID is my current email address, but I'm not renewing my domain and need a new email address. An icloud.com account seems an obvious choic
-
Problems upgrading to JDBC 5.1 driver for MS SQL Server
Hi, I recently upgraded to the Weblogic JDBC 5.1 driver for MS SQL Server and I am now receiving exceptions in my application when attempting to execute a prepared statement. I was previously using the Weblogic JDBC 4.x driver for MS SQL Server and e