16 (CASEWHEN TO_CHAR(to_date(dt,'YYYY/MM/DD'),'DY','nls_date_language=english')='SAT'THEN1ELSE0END) as Bus_Days_Diff
17
18from ifsinfo.RW_OUT_ORDERS_HIST_ONE_LAG
Best answer by durette
Your should have a calendar set up under Site from which you can exclude non-working days.
Here’s how to use the distribution calendar to achieve this. (On our system, this example shows that 5 working days separate last Wednesday and this Wednesday.)
Your should have a calendar set up under Site from which you can exclude non-working days.
Here’s how to use the distribution calendar to achieve this. (On our system, this example shows that 5 working days separate last Wednesday and this Wednesday.)
To solve the problem you have with adding HH24:MI:SS to your SQL-statements we need to know the data type of columns DT and LAG_DT in the IAL RW_OUT_ORDERS_HIST_ONE_LAG.
If it is VARCHAR2 or any other string data type we need to know the format of the data. (If data type is DATE there is no specific format.)
Thanks for the minutes API, that could be helpful.
The example doesn’t have HH:MM:SS included in the example so it’s not useful; we need # of hours between two full dates YYYY-MM-DD HH:MM:SS, excluding weekends.
What I meant with VARCHAR2 was an example of a string data type. All columns in your IAL view has a data type and if you do a to_char on a column with data type DATE the data type will be VARCHAR2.
I tried it and it works, however it looks like the minutes are low. Look at the first row. There are 17.6 days (including weekends); then 13 work days w/o weekends, yet the Hours (I took the minutes / 60) is only 111.18, when it should be around 13.6 * 24 = 326.4 hours.
I figured it out; I need two periods, not one, after &AO.
We have need to calculate the number of hours between 2 dates, minus weekends. We’re using the OrderHistory tab’s rows.
I have it working for just the number of days between 2 dates, and then did it for the number of hours (I simply removed TRUNC() around the 2 dates).
But that included weekends and now the team wants just business days. I was able find a solution for 2 dates, but it doesn’t include the hours.
I’m thinking the solution is to add HH24:MM:SS to the to_date() function but am receiving errors.
How do I format to_date() to include hours in the calculation?
1SELECTSite,OrderNo,status,lag_status,dt,lag_dt,TO_CHAR(to_date(dt,'YYYY/MM/DD'),'DY','nls_date_language=english') as DT_DAY,TO_CHAR(to_date(lag_dt,'YYYY/MM/DD'),'DY','nls_date_language=english') as LAG_DT_DAY, (to_date(dt,'YYYY/MM/DD') - to_date(lag_dt,'YYYY/MM/DD') ) - ((((TRUNC(to_date(dt,'YYYY/MM/DD'),'D'))-(TRUNC(to_date(lag_dt,'YYYY/MM/DD'),'D')))/7)*2) - (CASEWHEN TO_CHAR(to_date(lag_dt,'YYYY/MM/DD'),'DY','nls_date_language=english')='SUN'THEN1ELSE0END) - (CASEWHEN TO_CHAR(to_date(dt,'YYYY/MM/DD'),'DY','nls_date_language=english')='SAT'THEN1ELSE0END) as Bus_Days_Difffrom ifsinfo.RW_OUT_ORDERS_HIST_ONE_LAG
Page 1 / 1
Your should have a calendar set up under Site from which you can exclude non-working days.
Here’s how to use the distribution calendar to achieve this. (On our system, this example shows that 5 working days separate last Wednesday and this Wednesday.)
To solve the problem you have with adding HH24:MI:SS to your SQL-statements we need to know the data type of columns DT and LAG_DT in the IAL RW_OUT_ORDERS_HIST_ONE_LAG.
If it is VARCHAR2 or any other string data type we need to know the format of the data. (If data type is DATE there is no specific format.)
So are you saying in order to get HH:MM:SS we should use VARCHAR2() instead of TO_CHAR()?
Thanks for the minutes API, that could be helpful.
The example doesn’t have HH:MM:SS included in the example so it’s not useful; we need # of hours between two full dates YYYY-MM-DD HH:MM:SS, excluding weekends.
Good information, now I see the problem.
The columns DT and LAG_DT in the IAL are already strings on format YYYY-MM-DD so they do not contain the timestamp.
The cleanest way seems to be to remove the to_char in the IAL to get the two columns as data type DATE.
What I meant with VARCHAR2 was an example of a string data type. All columns in your IAL view has a data type and if you do a to_char on a column with data type DATE the data type will be VARCHAR2.
Example:
awesome, thx!
I tried it and it works, however it looks like the minutes are low. Look at the first row. There are 17.6 days (including weekends); then 13 work days w/o weekends, yet the Hours (I took the minutes / 60) is only 111.18, when it should be around 13.6 * 24 = 326.4 hours.
What am I missing?
The problem is that the calendar you have as Distribution Calendar in your site does only have work time for 8 hours a day.
You could check and see on the site which calendar you have and then go to this window to see the generated work minutes per day:
You must use another calendar which has 24 hours per day.
great, thx. Turns out we do have a calendar like that- named ‘5-24’. I plugged that in and now it works. Thx so much!
1ROUND(work_time_calendar_api.get_work_minutes_between('5-24',lag_dt,dt) /60, 2) as Bus_Hrs_API
When I try to put the API call in the IAL I get this error. I do have it prefaced with &A)..
I figured it out; I need two periods, not one, after &AO.
We use 3 different kinds of cookies. You can choose which cookies you want to accept. We need basic cookies to make this site work, therefore these are the minimum you can select. Learn more about our cookies.