Function to calculate the Minutes of business between two Dates
Hello
I use the version of database Oracle 11.2.1. I would like to calculate the number of minutes of work between the two dates where working hours are Monday - Thursday from 08:45 to 17:00 and Friday from 08:45 to 16:30
I found the following function useful in a similar position but wanted help picking up the days and the hours above into account
CREATE OR REPLACE
FUNCTION get_bus_minutes_between(
p_start_date DATE,
p_end_date DATE
)
RETURN NUMBER
IS
v_return NUMBER;
BEGIN
with t as (
select case level
when 1 then greatest(p_start_date,trunc(p_start_date) + 9 / 24)
else trunc(p_start_date) + level - 15 / 24
end start_dt,
case connect_by_isleaf
when 1 then least(p_end_date,trunc(p_end_date) + 18 / 24)
else trunc(p_start_date) + level - 8 / 24
end end_dt
from dual
connect by level <= trunc(p_end_date) - trunc(p_start_date) + 1
)
select sum(greatest(end_dt - start_dt,0)) * 24 * 60 work_minutes
into v_return
from t
where trunc(start_dt) - trunc(start_dt,'iw') < 5; -- exclude weekends
RETURN v_return;
END;
/
Can anyone help?
Hello
Think about what you do.
sliderrules wrote:
SELECT TO_CHAR (DATE ' 1-1-1' + business_end_time, 'HH24:MI:SS')-TO_CHAR (DATE ' 1-1-1' + business_start_time, 'HH24:MI:SS') * 24 * 60
of time_dim
where full_date = July 1, 2013.
AND working_day = 'Y ';
The following error is returned:
ORA-01722: invalid number
The time is converted to character reslting with this error. Is there a better way to subrtacting types of data INTERVAL DAY (1) SECOND (2) (business_end_time - business_start_time)
To_char, as its name implies, returns a string of characters. You say that
TO_CHAR (...) - TO_CHAR (...) * 24 * 60
If you ask for the string returned by the 2nd TO_CHAR be multiplied by 24. Does make any sense to you?
Maybe you wanted to do the subtraction first, which would be
(TO_CHAR (...) - TO_CHAR (...)) * 24 * 60
but still would be a mistake, because you can't subtract a string to another string (or anything else).
.
Last Friday, I proposed this:
SELECT SUM (LESS (end_dt, v_end_dt)
-Most GREAT (start_dt, v_start_dt)
) * 24 * 60...
where start_dt and end_dt were the DATE in the table columns, as the value returned by TO_DATE (08 11 July 2013:45 ', "DD-Mon-YYYY HH24").
If I understand correctly, you would store stores rather 3 columns: full_date (a DATE, where the time part is 00:00:00) as well as business_start_time and business_end_time (the two INTERVAL DAY TO SECOND). In this case, you can modify the code above to say:
SELECT SUM (LESS (full_date + business_end_time, v_end_dt)
-GREATEST (full_date + business_start_time, v_start_dt)
) * 24 * 60...
You can add a DATE at an INTERVAL; the result will be a DATE. There is no need to convert anything to a data type to the other.
Tags: Database
Similar Questions
-
Calculate the difference in days between two Dates
Hello
I'm trying to understand how to calculate the difference in days between two dates using JavaScript in LiveCycle. (Minimum = JavaScript knowledge)
Where 'Start_Date' and 'Current_Date' are the names of the two dates in the palette of the hierarchy. (the two Date/time field)
* Current date is using the object > value > execution property > current Date/time
I need a text or number field showing the difference in days. (Difference_in_Days)
I noticed the following code is pretty standard among other responses:
var
Start_date = new Date (Start_Date);
var
Current_Date = new Date (Current_Date);
var
nAgeMilliseconds = Current_Date.getTime) - Start_date.getTime ();
var
nMilliSecondsPerYear = 365 * 24 * 60 * 60 * 1000 ;
I know there is lack of code and code above are may not be not correct.
Please notify.
OK, that's because of the way that javascript and works of the calculate event. The field will be filled with whatever the script resolves at the end of execution. Technically, your script does not have a value because the last thing you do is an assignment to a variable. Change the last line as follows:
Math.ABS ((firstDate.getTime)
((- secondDate.getTime (()) / (oneDay));
(eliminate the variable assignment) and get rid of the app.alert. Your script will "return" (have) regardless of the value of calculation from the East and which will be stored in the field.
-
Calculate the number of days between two dates
Hello
Can someone help please change my formcalc script to calculate the number of working days between two date fields. My script currently calculates the total number of days between two dates, including the weekends which must be excluded from the total.
If
(HasValue (Start_Date1) & HasValue (End_Date1)) then
$
= Date2Num (End_Date1, "YYYY-MM-DD" "en_IE") - Date2Num (Start_Date1, "YYYY-MM-DD" "en_IE") + 1
on the other
""
endif
Any help will be most appreciated.
Thank you.
Check...
(1) you said that you put the script on the event «days1» calculate My sample imitates the variable names used in the original message, "Start_Date1" and "End_Date1". If the names of variables for the start and end dates are different, you will need to modify the script to account for these names.
(2) the Date2Num functions in the calculation of the "totalDays" use the date format "YYYY-MM-DD". If your date habits differ from "YYYY-MM-DD" FormCalc will complain.
Steve
-
Dynamically calculate the number of days between two dates and amounts of split
Hello
I have searched for a solution for this, but had no success.
I need to show the amounts broken down by days.
I have a table that has an amount column and start and end dates.
I need to write a query so that the amounts will be broken evenly based on the number of days between the start date and end date.
For example, for this line.
insert into my_test values (' 1, '' 3-mar-2010, ' 7 - mar - 2010 ", 1000);
the query returns this (split $1,000 over 5 days)
ID Date amount
1 ' 3-mar-2010' 200,00
1 ' 4-mar-2010' 200,00
1 ' 5-mar-2010' 200,00
1 ' 6-mar-2010' 200,00
1 ' 7-mar-2010' 200,00
create table my_test)
ID number (10),
start_date date,
End_date date,
amount number (10.2)
);
Select * from my_test
insert into my_test values (' 1, '' 3-mar-2010, ' 7 - mar - 2010 ", 1000);
insert into my_test values (2, 10-mar-2010 ", 19-mar-2010", 2000);
insert into my_test values (3, 20-mar-2010 ',' 21-mar-2010, 5000);
Thanks in advance.Hello
One way is to join a Meter of Table , a table, or (more often) a set of results includes a line for eery number 1, 2, 3,... until the maximum number of times you need to divide a line.
For example:WITH cntr AS ( SELECT LEVEL - 1 AS n FROM ( SELECT MAX (end_date - start_date) AS max_day_cnt FROM my_test ) CONNECT BY LEVEL <= 1 + max_day_cnt ) SELECT t.id , t.start_date + c.n AS dt , t.amount / (t.end_date + 1 - t.start_date) AS amt FROM my_test t JOIN cntr c ON c.n <= t.end_date - t.start_date ORDER BY id , dt ;
This assumes that all dates have the same number of hours, minutes, and seconds, as is the case in your sample data.
If this isn't the case, then use TRUNC (start_date) and TRUNC (end_date) instead of start_date and end_date or post some sample data and results if some lines do not represent a whole number of days. -
Dynamic calculation of the number of days between two dates in a table
Hello
I'm working on request where I dynamically calculate the number of days between two dates in a table.
The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.
APEX version: 5.0
Hi BO123,
BO123 wrote:
Hello
I'm working on request where I dynamically calculate the number of days between two dates in a table.
The calculation must be dynamic, i.e., when I recover the Start_date and End_date and move to the field following (call_duration) in the same row, the difference must be calculated dynamically in this area and make sure the field read-only.
APEX version: 5.0
one of the way to do this by calling ajax on change of end_date.
See the sample code given below to fetch the resulting duration and making the field read only after calculation
Step 1: Change your page
under CSS-> Inline, put the code below
.row_item_disabled { cursor: default; opacity: 0.5; filter: alpha(opacity=50); pointer-events: none; }
Step 2: Create on demand Ajax process I say CALC_DURATION
Please check Procces Ajax, see line 6.7 How to assign a value to the variable sent by ajax call
Declare p_start_date date; p_end_date date; p_duration number; Begin p_start_date := to_date(apex_application.g_x01); p_end_date := to_date(apex_application.g_x02); --do your calculation and assign the output to the variable p_duration select p_end_date - p_start_date into p_duration from dual; -- return calculated duration sys.htp.p(p_duration); End;
Step 3: Create the javascript function
Change your page-> the function and the declaration of the Global Variable-> put the javascript function
You must extract the rowid in the first place, for which you want to set the time, see line 2
assuming f06, f07 and f08 is the id of the start date, and end date columns respectively, and duration
See no line no 8 how set the value returned by the process of ajax at the duration column
Replace your column to the respective column identifiers in the code below
function f_calulate_duration(pThis) { var row_id = pThis.id.substr(4); var start_date = $('#f06_'+row_id).val(); apex.server.process ( "CALC_DURATION", { x01: start_date,x02: $(pThis).val() }, { success: function( pData ) { // set duration to duration column $('#f08_'+row_id).val(pData); // disable duration column $("#f08_" + row_id).attr("readonly", true).addClass('row_item_disabled'); } }); }
Step 4: choose the end date call the javascript function
Go to report attributes-> edit your Date column end-> column-> Attrbiutes element attributes-> put the code below
onchange="javascript:f_calulate_duration(this);"
hope this helps you,
Kind regards
Jitendra
-
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.
-
to calculate the number of days between 2 dates
Hi all
I need to calculate the number of days between 2 dates.
Y at - it no oracle built on that basis.
Thanks in advance
Kind regards
Nickuser646786 wrote:
HelloThanks a lot its really useful, but I must make a correction, I just want weekdays rather working days
As already said, there are many examples on the forum of the calculation of the working days or the days of the week or whatever you want between certain dates of restrictions. You will need to have a go at adapting what has already been given before and then when you get stuck, come here and your postcode, and someone will take a look for you.
-
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;
-
How to calculate the periods that overlap between two or more given the date range?
Hi all
If there are several durations then how we can calculate the period of time that overlap between these times.
For example: for 3 time periods. 03/12/2015-16/08/2015, 05/01/2015 to 31/07/2015 and the 06/09/2015 to 30/11/2015, how the overlap period can be calculated?
There are many potential unknowns in your question. For example, you want to count any overlap at all? If two dates overlap, what matters? Overlap - each of them?
In any case, here is a solution that counts how many periods are overlapping in any point in time... She, of course, using temporal logic. You can then use ValueAt(), WhenLast(), WhenNext(), etc. as appropriate.
Assume that your model has a child entity called 'the period' with name 'all time periods' relationship and basic attributes 'start date of the period of time' and 'date of end of period of time'.
In your example:
an entity should have the time period start date = 03/12/2015 and the date of end of period of time = 16/08/2015
another entity might have the time period start date = 01/05/2015 and the date of end of period of time = 31/07/2015
another entity might have the time period start date = 06/09/2015 and the date of end of period of time = 30/11/2015
To find the number of overlapping over time, we want to count or entities that have an active period, so the rule is perhaps the sum:
the number of overlapping = the number of all the periods for which it is true that the time period is active
How do we know a time is active? This is the time logic comes in. He is active on or after the start date or no later than the end date:
the time period is active if
TemporalOnOrAfter (the date of beginning of period of time) and
TemporalOnOrBefore (date of end of period of time)
That's all. Now, you can perform a temporal visualization of the 'number of overlapping' and you'll see it rise and fall over time. As a reference, he said that the number of overlapping = 3.0 from 06/09/2015 across 31/07/2015.
I hope this helps. You can use the same model to count periods of time functions, but you end up having to use the most logical date. You of course can count the total number of entities and compare this number of overlap over time to see if they overlap, but I digress...
-
How to find the difference "within weeks" between two date values?
Hi all
Jdev version 11.1.1.7.1
I used two < af:inputDate > & a < af:inputText > < af:panelFormLayout > components. My requirement is, I want to display the difference of weeks between these two day values in the inputText component when the user clicks the shape.
Any suggestion would be appreciated.
Kind regards
Novel
You can use this method to get the number of days between the day and date, and then divided by 7 to get the number of weeks
public static long getDifferenceDaysBetweenTwoDates (d1, d2 oracle.jbo.domain.Date oracle.jbo.domain.Date)
{
If (d1! = null & d2! = null)
{
return (d1.getValue () .getTime () - d2.getValue () .getTime ()) / (24 * 60 * 60 * 1000);
}
return 0;
}
Check - http://sameh-nassar.blogspot.in/2014/10/dealing-with-dates-in-java.html
Ashish
-
Need help on the list of months between two Dates
Hi all
I have a table which has startdate and enddate and need a select to list all the months between these two dates for each given ID.
I did some tests and could not figure out how to get the startdate and enddate table (instead of hard coding) tests in the select statement.
Could someone please help on this (Oracle 11 g 2),
Thanks in advance!
create table testing( id number, start_date date, end_date date); insert into testing values(100, to_date('05-FEB-2011', 'DD-MON-YYYY'), to_date('28-MAY-2011', 'DD-MON-YYYY')); insert into testing values(200, to_date('20-JUN-2011', 'DD-MON-YYYY'), to_date('28-DEC-2011', 'DD-MON-YYYY')); commit; select * from testing; ID START_DAT END_DATE ---------- --------- --------- 100 05-FEB-11 28-MAY-11 200 20-JUN-11 28-DEC-11 Elapsed: 00:00:00.01 *for testing.id = 100:* select to_char(add_months(to_date('05-FEB-2011', 'DD-MON-YYYY'), l - 1), 'YYYY-Mon') Dates from (select level l from dual connect by level <= months_between(trunc(to_date('28-MAY-2011', 'DD-MON-YYYY'), 'MONTH'), trunc(to_date('05-FEB-2011', 'DD-MON-YYYY'), 'MONTH')) + 1); DATES ----------------- 2011-Feb 2011-Mar 2011-Apr 2011-May Elapsed: 00:00:00.01 *for testing.id = 200:* select to_char(add_months(to_date('20-JUN-2011', 'DD-MON-YYYY'), l - 1), 'YYYY-Mon') Dates from (select level l from dual connect by level <= months_between(trunc(to_date('28-DEC-2011', 'DD-MON-YYYY'), 'MONTH'), trunc(to_date('20-JUN-2011', 'DD-MON-YYYY'), 'MONTH')) + 1); DATES ----------------- 2011-Jun 2011-Jul 2011-Aug 2011-Sep 2011-Oct 2011-Nov 2011-Dec 7 rows selected.
SQL> select * from testing 2 / ID START_DAT END_DATE ---------- --------- --------- 100 05-FEB-11 28-MAY-11 200 20-JUN-11 28-DEC-11 SQL> select id, 2 to_char(add_months(start_date,column_value - 1),'YYYY-Mon') dates 3 from testing, 4 table( 5 cast( 6 multiset( 7 select level 8 from dual 9 connect by add_months(trunc(start_date,'MM'),level - 1) <= end_date 10 ) 11 as sys.OdciNumberList 12 ) 13 ) 14 order by id, 15 column_value 16 / ID DATES ---------- -------- 100 2011-Feb 100 2011-Mar 100 2011-Apr 100 2011-May 200 2011-Jun 200 2011-Jul 200 2011-Aug 200 2011-Sep 200 2011-Oct 200 2011-Nov 200 2011-Dec 11 rows selected. SQL>
SY.
-
Calculation of the difference in days between two Dates
Hi all
I have two text fields with dates in them (P2_CURRENT_TIME_POINT_TEST_START_DATE, P2_ORGINAL_TEST_START_DATE). I would like to assign another text field (P3_TIME_FROM_INITIAL_TEST), the difference between the two days. I use a calculation page and tried suptracting them right or a date function diff, I found online, but nothing seems to work. Could someone lend me a hand on this one?
Thank you.Ben,
Sorry, please try the following:
:P3_TIME_FROM_INITIAL_TEST := TO_DATE(:P2_CURRENT_TIME_POINT_TEST_START_DATE, 'DD-MON-YYYY') - TO_DATE(:P2_ORGINAL_TEST_START_DATE, 'DD-MON-YYYY');
Remember to substitute the correct format string MON-DD-YYYY.
Kind regards
Danhttp://danielmcghan.us
http://sourceforge.NET/projects/tapigenYou can reward this answer by marking as being useful or correct ;-)
-
Dates of the fortnight of days between two dates
Hello
I want to show every fortnight dates based on the date, to date and the day of week (sunday, monday...)
Input parameters
Date: 31/05/2011
To date: 30/06/2011
day of week: Thursday
Output
06/02/2011
16/06/2011
30/06/2011
Input parameters
Date: 25/06/2011
To date: 30/06/2011
day of week: Monday
Output
27/06/2011
can someone help me?
Published by: user10594152 on May 30, 2011 22:10
Published by: user10594152 on May 30, 2011 22:19Hello
Here's one way:
WITH parameters AS ( SELECT DATE '2011-05-31' AS start_date , DATE '2011-06-30' AS end_date , 'Thursday' AS day_o_week FROM dual ) , got_dt AS ( SELECT end_date , NEXT_DAY ( start_date - 1 , day_o_week ) + (14 * (LEVEL - 1)) AS dt FROM parameters CONNECT BY LEVEL <= CEIL ( (end_date - start_date) / 14 ) ) SELECT dt FROM got_dt WHERE dt <= end_date ;
This ID on NLS_DATE_LANGUAGE load. If you do not what it is, you can change the sub-quewry like this:
WITH parameters AS ( SELECT DATE '2011-06-25' AS start_date , DATE '2011-06-30' AS end_date , TO_CHAR ( DATE '2011-05-30' -- or any Monday , 'Day' ) AS day_o_week FROM dual ) ...
Published by: Frank Kulash, 30 May 2011 13:13
Adding a warning about NLS_DATE_LANGUAGE -
PL/SQL function to calculate the non-working days
Hello
I have the following pl/sql function which generates a number of days between two selected dates (i.e. excluding weekends). However, I also need to exclude specific holidays - day of Christmas etc. These holiday dates are stored in a table in our database (11 GR 2) called "HOLIDAY".
How can I integrate the holidays which is held in the table of holidays in the following query to exclude these dates as well? I know how to write a separate funtion pl/sql for a number of days between two dates using SELECT... BUT I can't work out how to bring together them in a single query.
Could someone show me how with the pl/sql / dates below please?
Example of HOLIDAY table below.
Thank you!
TP
create or replace function WORKING_DAYS (pi_start_date in date, pi_end_date in date) return integer is v_start_date date :=pi_start_date; v_end_date date:=pi_end_date; v_count integer:=0; begin while v_start_date <= v_end_date loop if to_char(v_start_date,'D') not in ('6','7') then v_count := v_count+1; end if; v_start_date:=v_start_date+1; end loop; return v_count; end;
(select '10-Apr-2013' as NWD from dual union all select '06-May-2013' from dual union all select '27-May-2013' from dual union all select '26-Aug-2013' from dual union all select '26-Dec-2013' from dual union all select '25-Dec-2013' from dual union all select '01-Jan-2014' from dual union all select '18-Apr-2014' from dual union all select '21-Apr-2014' from dual union all select '05-May-2014' from dual union all select '26-May-2014' from dual union all select '25-Aug-2014' from dual union all select '25-Dec-2014' from dual union all select '26-Dec-2014' from dual) HOLIDAYS
Hello
the link is on MOSC, not OTN... Here's a copy:
This function calculates the number of days between two dates, ignoring weekends and holidays (if requested and if the holidays are stored in a table)
I give an example of table 'public_holiday' with sample data, but users must ensure that their table contains the relevant data (all holidays within the maximum range of use of the service)
CREATE TABLE public_holiday (calendar_day, DATE, text VARCHAR2 (30));
FUNCTION to CREATE or REPLACE nb_days (p_date_from IN DATE
p_date_to DATE by DEFAULT TRUNC (sysdate)
, p_public_holidays in CHAR DEFAULT 'Y '.
) RETURN NUMBER
DEFINE AUTHID
AS
/*********************************************************************/
/ * Author: Bruno Vroman * /.
/ * Created: 23-AUG-2012 * /.
/ * Last updated: 23-AUG-2012 * /.
/ * Object: to calculate the number of days between 2 dates, to the exclusion of * /.
/ * Saturday and Sunday, but also "holidays" If the * /.
/ * argument 'p_public_holidays' = 'Y ' * /.
/ * Support: p_date_from<= p_date_to ="">=>
/ * component ' hour min dry "ignored (just counting days) * /.
/* First step: */
/ * the calendar days between 2 days * /.
/ Remove 2 days for each "week" and 0 or 1 extra day * /.
/ * function to a condition "complex" mix day of first week * /.
/ * and the number of days when full remaining weeks are removed * /.
/ * (set up once for all, for example if there is 3 days and the * /)
(/ * first day is a Thursday, there is 1 "Sat/Sun" to subtract) * /.
/ * Second step: If 'p_public_holidays' = 'Y': other * /.
/ * days, do not count holidays. */
/ Holiday everyday are defined in a table "public_holiday" * /.
/ * Note: there may be holidays defined on Saturday/Sunday. */
/*********************************************************************/
l_result NUMBER;
l_from DATE;
l_to DATE;
l_case tank (4);
BEGIN
l_from: = TRUNC (p_date_from);
l_to: = TRUNC (p_date_to);
l_case: = TO_CHAR (l_from, 'Dy', 'NLS_DATE_LANGUAGE = English').
To_char (MOD (l_to - l_from + 1, 7));
l_result: = l_to - l_from + 1
-TRUNC ((l_to-l_from + 1) / 7) * 2
-CASE
WHEN l_case IN ('Mon6', 'Tue5', 'Wed4', 'Thu3', 'Fri2'
, "Sat1", "Sun1", "Sun2', 'Sun3", "Sun4".
, "Sun5', 'Sun6.
)
THEN 1
WHEN l_case IN ('Tue6', 'Wed5', 'Wed6', 'Thu4', "Thu5"
, 'Thu6', 'Fri3', 'Fri4', 'Fri5', 'Fri6 '.
, "Sat2", "Sat3', 'Sat4', 'Sat5", "Sat6.
)
THEN 2
0 OTHERWISE
END
;
IF SUPERIOR (p_public_holidays) = "Y".
THEN
SELECT l_result - COUNT (*)
IN l_result
OF public_holiday p
WHERE p.calendar_day > = l_from
AND p.calendar_day<=>=>
AND SUBSTR (TO_CHAR (p.calendar_day
, "Dy".
'NLS_DATE_LANGUAGE = English'
)
, 1, 1 ) != 'S'
;
END IF;
RETURN l_result;
EXCEPTION
WHILE OTHERS
THEN
DBMS_OUTPUT. Put_line (' CTF nb_days (' |))
To_char (p_date_from, "MON-DD-YYYY"). ', ' ||
To_char (p_date_to, "MON-DD-YYYY"). ', ' ||
p_public_holidays | ' ) : ' || SQLERRM
);
LIFT;
END nb_days;
/
REM
REM example:
REM A) fill out the 'public_holidays '.
REM
TRUNCATE TABLE public_holiday;
INSERT INTO public_holiday VALUES (DATE ' 2012-01-01', ' new year (a Sunday)');
INSERT INTO public_holiday VALUES (DATE '' 2012-01-03, "for example");
REM (insert other days...)
COMMIT;
Call the function for some pairs of dates of REM B)
REM nb1: remove only Sat/Sun
REM nb2: also remove holidays
REM
ALTER SESSION SET nls_date_format ='Dy DD-MON-YY';
WITH some_dates AS
(SELECT DATE ' 2011-12-29'd dual FROM
UNION ALL SELECT DATE ' 2012-01-08' FROM dual
UNION ALL SELECT DATE ' 2012-01-10' FROM dual
)
SELECT d1.d 'FROM '.
, d2.d ' to THE '.
, nb_days (d1.d, d2.d, ' don't) nb1
, nb_days (d1.d, d2.d, 'Y') nb2
OF some_dates d1
some_dates d2
WHERE d1.d<=>=>
ORDER BY nb1, nb2, d1.d
;
GO TO NB1 NB2
------------- ------------- ---- ----
Monday, January 8, 12 Monday, January 8, 12 0 0
Friday, December 29, 11 Friday, December 29, 11 1 1
Wednesday, January 10, 12 Wednesday, January 10, 12 1 1
Monday, January 8, 12 Wednesday, January 10, 12 2 2
Friday, December 29, 11 Monday, January 8, 12 7 6
Friday, December 29, 11 Wednesday, January 10, 12 9 8
Hope that this could be useful, but note that this code has not been completely tested, so check and test before you trust it (in the case of any questions, please post a comment)
Bruno Vroman.
Best regards
Bruno
-
Calculate the (age) years between two dates
Nice day!
I have not been able to find an answer, that I was able to use in the archives or online and would be very grateful for the help. I'm working with Adobe Acrobat Pro XI (not LiveCycle) and I have very little experience with programming (for the most part, copy / paste).
I need to create a text box that calculates the number of years between two dates entered, i.e. the age when the date of birth and death are given. Also, would be nice if she was a Virgin until the two were provided. Anyone would be able to give me the code I need to put in the custom calculation script?
Once again, any help would be much appreciated! Thank you and have a wonderful day!
For the fields for Date of birth DOB and DOD for the Date of death and age in complete years both by using a'd-mmm-yyyy' date format you can use a custom calculation to the JavaScript for the field of age as:
function GetField (cName) {}
get the field with error trapping object;
oField var = this.getField (cName);
test error;
if(oField == null) app.alert ("error during the" + cName, 1, 0);
Returns the field object;
return oField;
} / / end GetField function;function {Scand (cFormat, cString)
using date string format convert object date;
convert string to date using format;
Kai var = util.scand (cFormat, cString);
the value null is an error of conversion;
if(oDate == null) app.alert ("Conversion error" cString "by using the format" + cFormat, 1, 0);
date of return;
Return to oDate;
} / / end Scand function;clear the value of the field;
Event.Value ="";
get data dob and dod;
var oDOB = GetField ("DOB");
Var o = GetField ("DOD");treat only if DOB and DOD have value and are not null;
If (oDOB! = null & o! = null & oDOB.value! = "" & oDOD.value!) = "") {}convert the DOB and DOD to date objects.
oDOB var = util.scand ("d-mmm-yyyy", oDOB.value);
O var = util.scand ("d-mmm-yyyy", oDOD.value);get the difference over the years;
var Age = oDOD.getFullYear () - oDOB.getFullYear ();adjust for month of previous DOD DOB;
If (oDOD.GetMonth)< odob.getmonth())="">adjust the DOD before DOB date in the month of birth;
If (oDOD.GetMonth () == oDOB.getMonth () & oDOD.getDate ())< odob.getdate())="">
Set the value of the field;Event.Value = Age;
}
Maybe you are looking for
-
I once had a problem with Windows Update, which gives me a family of .NET Framework through the window of Control Panel\Windows to update to Windows Vista, even if it has been installed and has Microsoft support help me through EasyAssist. The proble
-
I am having a very strange problem with WMP 12 in WINDOWS 7
Hello. I could use some help. A bit of background. HP can not solve the problem (I have a contract with the manufacturing service). I used this drive for 2 years without a lot of questions. I have more than 400 albums in my library. I got a new CD, s
-
Replace HARD drive and then reloading the system op.
Have a desktop hp a6518f with a bad hdd. If I replace the original hdd with 500 MB (1-1, 5 to) one, backup/restore disks, that I did install work to recharge the system op (Vista Home Premium)? Y at - it any other way, other than buy & install Win
-
I have a secondary e-mail (Gmail) account that I use for my Google Calendar, so I need to save to maintain synchronized calendar on my Blackberry. But I don't want emails from this account sent to my Blackberry. (Emails from this account are already
-
ACS 5.3 vmware Workstation Ubuntu
Hello I managed to install ACS 5.3 on vmware 8.0.4 (Ubuntu 12.04). I can connect but I have some fatal errors from the server ({0} or 500) when you work wihthin access policies. I can not change (or same) selection of selection of unique result of se