To calculate the amount on the basis of the date of
Hello
We must consider the functionality of oracle when it sees in 365 days a year. (for leap years 366 days)
calendar year of 365 days. calendar year of 12 months. Months will track the number of calendar days in the month. For example the Feb has 28 days and Oct. has 31 days.
Example:
For the period from 27/06/12 to 20/08/12
Annual amount of $3214.
Calculation
$3214 / 12 months = $267,83 per month
For June, $267,83 / 30 days in a month = $8.93 daily rate
6/27-6/30 is 4 days of service. x 4 = $35,72 $8.93
7/1-7/31 is considered to be a full month. = $267,83
For August, 8/1 /-8/20 is considered to be 20 days. Per day = 267.83 / 31 = 8.64
20 days = $172.79
TOTAL = $476,34
Please help me on how to do the following calculations.
Concerning
Suresh
Another solution, works better than the previous:
with the data as
(
Select to_date (June 27, 2013 ',' DD/MM/YYYY ') from_dt, to_date (August 20, 2013 ',' DD/MM/YYYY ') to_dt, amt double 3214
)
Select sum (DM)
de)
Select from_dt, to_dt, start_dt, last_dt,
(last_dt - start_dt + 1) *--> multiply applicable days of the month at the daily amount, calculated below
Sum)
round)
(amt/12) /--> calculate a monthly amount
TO_CHAR)
LAST_DAY (curr_dt)
, 'DD '.
)--> Find last day of the month and divide the monthly amount with the last day and calculate the daily amount
2
)--> Around the daily amount to 2 decimal places
) on sm--> sum the amount daily (partition to_char (curr_dt, 'MM'))
de)
Select from_dt, to_dt, TN,
less (add_months (from_dt, level - 1), to_dt) curr_dt,.
decode (level 1, less (add_months (from_dt, level - 1), to_dt), trunc (less (add_months (from_dt, level - 1), to_dt), 'MM')) start_dt;
less (last_day (add_months (from_Dt, level - 1)), to_dt) last_dt
from the data
connect by level<= months_between(trunc(to_dt,="" 'mm'),="" trunc(from_dt,="" 'mm'))="" +="">=>
)
);
SUM (DM)
----------------------
476.36
This avoids looping of data for all of the Dates if opposed to a loop for each month, which increases its performance. See plans to explain to the two queries:
explain plan for
with the data as
(
Select to_date (June 27, 2013 ',' DD/MM/YYYY ') from_dt, to_date (August 20, 2013 ',' DD/MM/YYYY ') to_dt, amt double 3214
),
div_data as
(
Select from_dt, to_dt, annual_amount from the amt Tower (amt/12, 2) monthly_amount
from the data
)
Select sum (per_day_amt)
de)
Select to_char (level - 1, 'Lun' + from_dt) curr_dt,.
sum (round (monthly_amount/to_number (substr (to_char (last_day (level - 1 + from_dt), 'DDMMYYYY'), 1, 2)), 2)) per_day_amt
of div_data
connect by level<= (to_dt="" -="" from_dt)="" +="">=>
To_char Group (level - 1, 'Lun' + from_dt)
);
Hash value of plan: 1042012692
----------------------------------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
----------------------------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 13. 5 (20) | 00:00:01 |
| 1. TRANSFORMATION OF THE TEMPORARY TABLE. | | | | |
| 2. LOAD SELECT ACE | | | | | |
| 3. QUICK DOUBLE | | 1. | 2 (0) | 00:00:01 |
| 4. GLOBAL TRI | | 1. 13. | |
| 5. VIEW | | 1. 13. 3 (34) | 00:00:01 |
| 6. HASH GROUP BY. | 1. 16. 3 (34) | 00:00:01 |
|* 7 | CONNECT TO WITHOUT FILTERING. | | | | |
| 8. COUNT | | | | | |
| 9. VIEW | | 1. 16. 2 (0) | 00:00:01 |
| 10. TABLE ACCESS FULL | SYS_TEMP_0FD9D86CF_5F8521E2 | 1. 44. 2 (0) | 00:00:01 |
----------------------------------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
7 filter (LEVEL<>
explain plan for
with the data as
(
Select to_date (June 27, 2013 ',' DD/MM/YYYY ') from_dt, to_date (August 20, 2013 ',' DD/MM/YYYY ') to_dt, amt double 3214
)
Select sum (DM)
de)
Select from_dt, to_dt, start_dt, last_dt,
(last_dt-start_dt + 1) * sum (round ((amt/12)/to_char (last_day (curr_dt), 'JJ') 2)), in the sm (partition to_char (curr_dt, 'MM'))
de)
Select from_dt, to_dt, TN,
less (add_months (from_dt, level - 1), to_dt) curr_dt,.
decode (level 1, less (add_months (from_dt, level - 1), to_dt), trunc (less (add_months (from_dt, level - 1), to_dt), 'MM')) start_dt;
less (last_day (add_months (from_Dt, level - 1)), to_dt) last_dt
from the data
connect by level<= months_between(trunc(to_dt,="" 'mm'),="" trunc(from_dt,="" 'mm'))="" +="">=>
)
);
Hash value of plan: 1669308594
-----------------------------------------------------------------------------------------
| ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
-----------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | 1. 13. 3 (34) | 00:00:01 |
| 1. GLOBAL TRI | | 1. 13. | |
| 2. VIEW | | 1. 13. 3 (34) | 00:00:01 |
| 3. KIND OF WINDOW. | 1. 30. 3 (34) | 00:00:01 |
| 4. VIEW | | 1. 30. 2 (0) | 00:00:01 |
|* 5 | CONNECT TO WITHOUT FILTERING. | | | | |
| 6. QUICK DOUBLE | | 1. | 2 (0) | 00:00:01 |
-----------------------------------------------------------------------------------------
Information of predicates (identified by the operation identity card):
---------------------------------------------------
5 filter (LEVEL<>
Post edited by: PurveshK
Updated with explanation.
Tags: Database
Similar Questions
-
PDF Acroform Javascript (WIN): Calculate the Date of next Tuesday
03/06/10
Greetings;
I found a javascript script that will calculate the date of next Tuesday, but I can't seem to make it work in Acrobat Pro v8 (Acroforms).
Any help / guidance you can provide is appreciated the most.
Script:
http://Christian.lassem.com/js/JavaScript-next-Tuesday/
JavaScript to find next Tuesday?
function find_date_of_next_tuesday() {}
var today = new Date();
today.setDate (today.getDate () + 1);
While (today.getDay ()! = 2) {}
today.setDate (today.getDate () + 1);
}
return (today.toDateString ());
}Thanks in advance.
You just need to call this function, and then use the string that it returns. What
does not work, exactly?
-
How to calculate the date interval
Hi Experts,
I'm looking for a way to calculate the interval between two dates. And get the result to the format "dd.mm.yyyy hh24:mi:ss.
Best practices for a problem like this?select sysdate - to_date('1.1.2000 12:00:00','dd.mm.yyyy hh24:mi:ss') from dual
Best regards
Igorselect trunc( months_between( day2, day1 ) / 12 ) years , mod( trunc( months_between( day2, day1 ) ), 12 ) months , numtodsinterval( day2 - add_months( day1, trunc( months_between( day2, day1 ) ) ), 'DAY' ) rest from ( select to_date( '19-01-1979', 'dd-mm-yyyy' ) day1, sysdate day2 from dual )
-
How to calculate the data according to the fiscal
I want to dispaly the result for the accounting year from April to March for any accounting year (Accounting year is from April to March). I have a table INVOICE. CREATE TABLE INVOICE ( IN_NO NUMBER, IN_DT DATE, IN_DETAILS VARCHAR2(20 BYTE) ) I want to calculate display the result for accounting year from April 2010 to March 2011, and from April 2011 to MArch 2012. What statement should i use to filter the data as above ? Sanjay
user12957777 wrote:
I want to dispaly the result for the accounting year from April to March for any accounting year (Accounting year is from April to March). I have a table INVOICE. CREATE TABLE INVOICE ( IN_NO NUMBER, IN_DT DATE, IN_DETAILS VARCHAR2(20 BYTE) ) I want to calculate display the result for accounting year from April 2010 to March 2011, and from April 2011 to MArch 2012. What statement should i use to filter the data as above ? Sanjay
You should now learn to use correctly
tags select to_char(add_months(in_dt,-3),'YYYY') FISCAL_YEAR FROM INVOICE;
-
Calculate the Date of the next
Hello
I have two dates:
Start date: December 18, 2007
End date: December 18, 2012
I would like to calculate the next payment date, using the example above, it would be December 18, 2010.
How can I achieve this in SQL by using the current date / month, keeping in mind, if sysdate is past the date, then the next payment date will follow month.
Thank you
Published by: sliderrules on December 15, 2010 08:50Hello
Assuiming the due date is the same day of the month (if possible) as start_date:
SELECT start_date , ADD_MONTHS ( start_date , CEIL ( MONTHS_BETWEEN ( SYSDATE -- or maybe SYSDATE + 1 , start_date ) ) ) AS next_payment_date FROM table_x ;
If you happen to run it on December 18, the expiry date should be December 18 or January 18?
The code above returns on 18 December. If you want Jnauary 18, replace SYSDATE SYSDATE + 1.Assuiming that the due date is the same day of the month (if possible) as end_date, you could do something similar with the help of end_date.
Whatever it is, only one of the columns plays a role in this problem? What results would you if, for example. start_date was January 1, 2010 and July 20, 2012 end_date?I hope that answers your question.
If not, post a small example of data (CREATE TABLE and INSERT statements) and also publish outcomes from these data. For the results, after what you want if it was executed on 15 December 2010 at noon.
Explain, using specific examples, how you get these results from these data.
Always tell what version of Oracle you are using. -
Calculate the date of the first or last in a quarter
Hello
I have data of project with a start date and end date I need to calculate the number of days per quarter
project x: 15/03/06 - 15/05/06
15 days Q1 = Q2 = 45 days
I'm then going to calculate the percentages of resource. I can get the bt of the watch with a hack of a time to identify the first or the last day of a given quarter. Any help win my sincere admiration.
Sorry, misread the question. The district will rely on the company that you work for. If the end of his is the same as an end of year calendar (31 December), then the example below will be accurate. Change the dates according to the needs of the company.
You can hardcode the variables in your application.cfm page.
quarter1start = "01 - jan -";
quarter2start = '01 - apr -';
quarter3start = "01 - jul -";
quarter4start = '01 - oct -';Programatically, the end of each quarter is always the day before the start of the next quarter.
I would add "year" to the equation dynamically, to keep in it before compatible. -
How to calculate the date from sysdate
I try to get 12/09/2009-12:51:30 by subtracting the current date to sysdate.I can get with this year, but I don't know how I can get to the date and the month preceding.
() Choose add_months (sysdate-36() of double) = 12/09/2010
Planned result 12/09/2010 13:23:30
Thank you for the help
I'm assuming that time is fixed if it is to see the example below.
SQL > select add_months (to_date (to_char(sysdate,'dd-mon-yyy') |)) (("" 12:51:30 ',' dd-MON-yyy hh: mi: ss AM "), - 36) prior_date
2 double;PRIOR_DATE
-----------------------
12 - Oct - 2010 12:51:30SQL >
-
PowerCLI does not calculate the Date year statement
Hello
I have a custom to attribute Date (JJ/MM/AAAA) in vCenter and I attempt to bring together WHAT VM before that date but does not my statement appear to account for the year. So if I put a date in the future for example 15/01/2012 the script lists than before the current date is incorrect and everything goes back beyond the date of the day but still in 2011 is not displayed is correct. Any ideas would be greatly appreciated.
$currentdate = get-Date
$currentdate = $currentdate. ToShortDateString()Get - VM | Get-Annotation - CustomAttribute "Expires"? {$_. Value - the "$currentdate"} ' "
Version:
vCenter - 4.1.0.12319
PowerCLI - 4.1.1.2816
See you soon!
Have you thought about converting the date you get the attribute. Try this
$currentdate = get-Date
Get - VM | Get-Annotation - CustomAttribute "Expires"? {(Get-Date $_.)} The value) - $currentdate}
-
Calculate the Date difference in the session variable
I use the following to try to establish the number of difference in days between the dates of two different recordsets. The result using test data should be 15, but I get 0. No code error message, but no accurate result either. I checked the date two values involved, and they send the data appropriate to the right format... just can't get the DateDiff function to work in the session... variable all help greatly apprciated.
Code:
< % Session("Lead") = DateDiff ([d], [rsSurvey.Fields.Item("tblShipDat"). Value], [rsOrder.Fields.Item("tblValDat"). % of value]) >Thank you very much for any assistance... it was indeed the brackets surrounding table columns names that have crossed upwards. Correct solution:
< %="">< br="">Session("Lead") = DateDiff ("d", rsSurvey.Fields.Item("tblShipDat"). Value,< br="" >="" rsorder.fields.item("tblvaldat").="" valeur)="">< br="" >="" %="">
All entries are greatly appreciated. Really the non-professional coder help advance...
Kind regards
Chris Robinson
-
How to calculate the date fields while excluding Saturday and Sunday
Hi, I use Jdeveloper 11.1.3.4
I have an Oracle database and creates a table called holiday with 3 attributes:
user (VARCHAR)
(early)
end (date)
The idea is that you subtract the finish from the beginning and get a number of vacation days used. The thing is that the sum should exclude Saturday and Sunday.
Any way to do it?/* Formatted on 6/1/2011 7:57:32 AM (QP5 v5.149.1003.31008) */ WITH t AS ( SELECT id, MAX (strt) strt, MAX (finish) finish, SUM (dys) days_off FROM (SELECT id, strt, finish, CASE WHEN TO_CHAR (dy, 'day') LIKE 'saturday%' THEN 0 WHEN TO_CHAR (dy, 'day') LIKE 'sunday%' THEN 0 ELSE 1 END dys FROM vacations MODEL PARTITION BY (ID id) DIMENSION BY (0 d) MEASURES (POCETAK strt, KRAJ finish, POCETAK dy) RULES (dy [FOR d FROM 1 TO finish[0] - strt[0] INCREMENT 1] = (NVL (dy[CV () - 1], dy[CV ()]) + 1))) GROUP BY id ORDER BY id) SELECT t.id, t.strt, t.finish, t.days_off, vacations.korisnik, SUM ( CASE WHEN finish < TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off ELSE 0 END) OVER (PARTITION BY vacations.korisnik ORDER BY t.id) this_years_running_total, SUM ( CASE WHEN finish < TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off ELSE 0 END) OVER (PARTITION BY vacations.korisnik) this_years_grand_total, SUM ( CASE WHEN finish >= TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off ELSE 0 END) OVER (PARTITION BY vacations.korisnik ORDER BY t.id) next_years_running_total, SUM ( CASE WHEN finish >= TO_DATE ('01/07/2011', 'dd/mm/yyyy') THEN days_off ELSE 0 END) OVER (PARTITION BY vacations.korisnik) next_years_grand_total FROM t, vacations WHERE t.id = vacations.id
id strt finish daysoff korisnik thisyrruntot thisyrtot netyrruntot nextyrtotal 1 5/25/2011 5/31/2011 5 Kantardzic 5 22 0 26 2 6/6/2011 6/13/2011 6 Kantardzic 11 22 0 26 5 6/1/2011 7/6/2011 26 Kantardzic 11 22 26 26 6 6/16/2011 6/30/2011 11 Kantardzic 22 22 26 26
-
Calculate the interval in days
Hi all!
I need your help.
I have an oracle sql table.
This is going to...
TABLENAME: RACE
DATE NAME
JANUARY 11, 12 JAMES
JAMES JANUARY 12, 12
JAMES JANUARY 14, 12
JAMES JANUARY 17, 12
JAMES 22 JANUARY 12
1 FEBRUARY 12 JOHN
FEBRUARY 11, 12 JOHN
JOHN 13 FEBRUARY 12
JOHN 14 FEBRUARY 12
28 FEBRUARY 12 JOHN
JOHN 1ST MARCH 12
HOW can I calculate the date total interval (difference) for James and John in days?
for example in this case total is 7 days for James (January 11, 12 to 12 January 12 is 0 days and 12 January 12 to January 14, 12 is 1 day and 14 January 12 to 17 January 12 is 2 days) and 24 days for John
Data for the date will be random and can be up to names and dates of difference 60 so I would like to calculate all the names of different... Thank you!Is there anyway that I can query without listing all the date?
Yes, just use the lower part of the "Real application" comment, that is:
select max(dt)-min(dt)-count(*)+1 diff , nm from race group by nm;
I used the WITH only clause to generate some testdata...
-
I want to calculate the date to end date of beginning period, but I have problem
For example, my start date is 'August 21, 2011' and my End Date is "August 21, 2012".
So I want to result as months of the year and days like this is "2 YEARS".
I wrote this command from pl/sql, but I figured it
"TWO YEARS AND SIX DAYS."
Please tell me how to calculate this period
I have enclosed my query
----------------- QUERY ----------------------
Declare
number of mtot_days;
number of mdays;
number of myears;
number of mmonths;
V_Month Varchar2 (10);
V_Year Varchar2 (10);
V_Days Varchar2 (10);
Start
break;
mtot_days: days = (: from_date,: to_date);
myears: = floor(mtot_days/365);
mmonths: = floor(mtot_days/30);
If mmonths = 12 then
mmonths: = 0;
end if;
Mdays: = mod(mtot_days,30);
If mmonths = 1 then
V_Month: = "MONTHS";
on the other
V_Month: = "MONTHS";
End If;
If myears = 1 then
V_Year: = "YEAR";
on the other
V_Year: = "YEARS";
End If;
If mdays = 1 then
V_Days: = "DAY";
on the other
V_Days: = "DAYS";
End If;
If myears = 0 and mmonths! = 0 and mdays! = 0 then
: period: = mmonths | ' ' || V_Month | «AND» | Mdays | ' ' || V_DAYS;
ELSIF
Mdays = 0 and mmonths! = 0 and myears! = 0 then
: period: = myears | ' ' || V_Year | «AND» | mmonths | ' ' || V_Month;
ELSIF
mmonths = 0 and myears! = 0 and mdays! = 0 then
: period: = myears | ' ' || V_Year | «AND» | Mdays | ' ' || V_Days;
ELSIF
myears = 0 and = 0 and mdays mmonths! = 0 then
: period: = mdays | ' ' || V_Days;
ELSIF
Mdays = 0 and = 0 and myears mmonths! = 0 then
: period: = myears | ' ' || V_Year;
ELSIF
Mdays = 0 and = 0 and mmonths myears! = 0 then
: period: = mmonths | ' ' || V_Month;
ELSIF
Mdays! = 0 and myears! = 0 and mdays! = 0 then
: period: = myears | » ' || V_Year | » ' || mmonths | » ' || V_Month | ' AND ' | Mdays | » ' || V_Days;
on the other
: period: not = "ANY TIME."
End If;
end;not every month has 30 days. Use ADD_MONTHS() instead:
SET SERVEROUTPUT ON DECLARE v_start DATE := TO_DATE('21-AUG-2011', 'DD-MON-RRRR'); v_end DATE := TO_DATE('22-JUN-2014', 'DD-MON-RRRR'); v_cnt_years NUMBER := 0; v_cnt_months NUMBER := 0; v_cnt_days NUMBER := 0; v_date DATE; BEGIN v_date := v_start; WHILE ADD_MONTHS(v_date, 1) <= v_end LOOP v_date := ADD_MONTHS(v_date, 1); v_cnt_months := v_cnt_months + 1; IF v_cnt_months = 12 THEN v_cnt_years := v_cnt_years + 1; v_cnt_months := 0; END IF; END LOOP; v_cnt_days := v_end - v_date; -- DBMS_OUTPUT.PUT_LINE( TO_CHAR(v_start, 'DD-MON-RRRR') || ' - ' || TO_CHAR(v_end, 'DD-MON-RRRR') || ': ' || v_cnt_years || ' Years, ' || v_cnt_months || ' Months, ' || v_cnt_days || ' Days'); END; /
outpupt vor several ranges:
21-AUG-2011 - 20-AUG-2012: 0 Years, 11 Months, 30 Days 21-AUG-2011 - 21-AUG-2012: 1 Years, 0 Months, 0 Days 21-AUG-2011 - 22-AUG-2012: 1 Years, 0 Months, 1 Days 21-AUG-2011 - 22-JUN-2014: 2 Years, 10 Months, 1 Days
Published by: Serge the 25.03.2011 10:46
-
How do I get the date of last Saturday
Hello
How can I calculate the date of last SaturdayIND > select sysdate double;
SYSDATE
---------------------
08 - jun - 11:04:43:36:pm1 selected line.
IND > NEXT_DAY(sysdate,'SAT') SELECT-double 7;
NEXT_DAY (SYSDATE,'SAT)
---------------------
04 - jun - 11:04:43:44:pm1 selected line.
-
To add minutes in the Date column
Hello..
I just wan to calculate the date with timestamp after addition of minutes.
I had the time (date column), I wan to calculate the column date of to_time according to the minutes, we added time (date column).
can u please help me... As soon as possible...Hello
It would have been better if you would have given a sample input and output. So to add a minute
update table xyz set to_time = from_time + (number of minutes)/24/60
Something as above can be done.
Concerning
Anurag -
variable presentation changing the data type date to string the Calende
Hi gurus,
I'm having a strange problem. I have a Start date and end date fast that aren't on any column presentation for example (in the case where 1 = 0 DATE. DATE other cast ('2100-12-31 Date ') end).
Now, this prompt, I put 2 startdate and enddate variables presentation to use in my sql filter in the report.i use these variable to calculate the date for these 2 end dates and then I apply between it function with these 2 dates.
The question is when the dashboard is running for the first time the presentation variable takes the dates as the DATE "' 2009/14/10 and when I change the date and click on the go button, the variables is October 15, 2009" as strings anf so DATE in my SQL filter functions fails and error throughts VD.
All of the suggestions!Nico explain already.
Select date '' 2009-12-15 of the double - TRUE
Select date of 2009 '-15-12' of the double - ORA-01843: not one month valid
Select date ' 10/2009/15 ' of double - ORA-01861: literal does not match the format stringDATE 'yyyy-mm-dd' does that have this format.
Concerning
Goran
http://108obiee.blogspot.com
Maybe you are looking for
-
Hello A work of Radeon 5450 1 GB on a Slimline s3321p with 160w power ahead? I heard that a 5450 is the best graphics card to upgrade a tapered, with a power supply 160w without upgrading of power supply. All the specifications of my computer are alw
-
WIN 7-64 bit / printer EPSON EPL-5800 L driver
Hey,.is there anyone who knows a source for the above printer driver?The former (NT) who does not work with my new laptop satellite L 550 d-12Fthx a lotthpuc
-
Cannot send email from my Windows Mail Outbox
Have used my Windows Mail to send for years and yesterday this message whenever I try to send an email. I can still receive emails. I am not very computer and so do not know what to do. Any help most appreciated. "An unknown error has occurred. S
-
I can't program my defrag to run only the Cancel button is turned on, not on the ok button
How can I program my Defrag to run every week? When I try only the Cancel lights if I hit the ok button nothing happens
-
Taskbar and Start Menu customization errors
I turned on my computer today, and my taskbar has been replaced with the classic windows style. I tried to go back to windows vista style and I received this error message. "The Visual styles could not be applied." When I chose the option of windo