Pick latter or two dates for calculation
Hello all,
I am new to discoverer and just came accross a request to do a calculation on a report that would show the difference between two dates. The first date is always the same field but the second is the latter date from two different fields. Is there a way to do that in discoverer? Without writing a custom function on the db server.
Thanks
Hi,
Use (default_date-(GREATEST(folder.date1,folder.date2)) in the calculation.
It should work.
Thanks.
Similar Messages
-
Use Date() for calculation
Dear sir,
I want to know how to use Date() for calculation.
For example:
int rentday = 7;
today = new Date();
I want to add today and rentday to get dueday. I've try to use "dueday=today + rentday", but error.
Pls help!!! Thanks!!!Hi "acos3ltd",
I think, perhaps, that the "java.util.GregorianCalendar" class may be what you require:
http://java.sun.com/j2se/1.4.1/docs/api/java/util/GregorianCalendar.html
and this Web page may also be of help:
http://java.sun.com/people/linden/faq_b2.html#Date
Hope it helps.
Good Luck,
Avi. -
Find the difference between two dates for the specific month and year
Hi,
I have two dates, start date is 30/12/2012 and end date is 04/01/2013. Using datediff I found the difference of days between two dates. But I find the no of days in January 2013. ie output is 4 instead of 6. I input month and year to find the no of days
for that date. In this case I input Jan 2013. How can I sql this ?I don't understand how most of the answers provided here not analytically solving the problem with many cases possible.
First let me understand you:
You have 2 dates range and you want to calculate day range for specific month and year between the original date range.
declare @for_month int = 1 --January
declare @for_year int = 2013
declare @StartDate date = '2012-12-20'
declare @EndDate date = '2013-01-04'
SELECT
CASE
WHEN (DATEPART(MONTH, @StartDate) = @for_month and DATEPART(MONTH, @EndDate) = @for_month) and ((DATEPART(YEAR, @StartDate) = @for_year or DATEPART(YEAR, @EndDate) = @for_year)) THEN
DATEDIFF(DAY, @StartDate,@EndDate)
WHEN (@StartDate < cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (@EndDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
DATEDIFF(DAY, DATEADD(MONTH, DATEDIFF(MONTH, -1, @EndDate)-1, 0),@EndDate)
WHEN (@EndDate > cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) and (@StartDate between (cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) and (cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date))) THEN
DATEDIFF(DAY, @StartDate,DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, @StartDate) + 1, 0))) + 1
WHEN ((DATEDIFF(DAY, @StartDate, cast(DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date)) + 1, 0)) as date)) >= 0) and (DATEDIFF(DAY, cast(CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as date), @EndDate) >= 0)) THEN
DATEDIFF(DAY, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime), DATEADD(d, -1, DATEADD(m, DATEDIFF(m, 0, cast( CONVERT(varchar(4), @for_year) + '-' + CONVERT(varchar(2), @for_month) + '-01' as datetime)) + 1, 0))) + 1
ELSE
0
END as [DD]
I don't know how you calculate day range between 01/01/2013 and 04/01/2013
is 4, it is actually is 3 but if that is the case, you can add 1 from the condition. -
[SOLVED] SQL QUERY 22 (10pm) to 06 am between two dates for shift work
i have done a query like this
SELECT * FROM RCV_SHIPMENT_HEADERS
WHERE TO_CHAR(CREATION_DATE,'DD-MON-YYYY HH24:MI:SS') BETWEEN '02-FEB-2011 22:00:00' AND '03-FEB-2011 06:00:00'
ORDER BY 1,4
i didn't get good result please help me
Edited by: 950688 on Aug 9, 2012 10:41 PMI GOT SOLUTION
SELECT * FROM rcv_shipment_headers
WHERE creation_date > TO_DATE('02-FEB-2011 22','DD-MON-YYYY HH24') --02-FEB-2011 22
AND creation_date <= TO_DATE('02-FEB-2011 06','DD-MON-YYYY HH24')+1 --02-FEB-2011 06
THANK YOU FOR YOUR ASSISTANCE
Edited by: 950688 on Aug 9, 2012 10:40 PM -
Using pl/sql function for each day between two dates.
Hi,
create TABLE EMP(
ID_EMP NUMBER,
DT_FROM DATE,
DT_TO DATE,
CREATE_DATE DATE);
into EMP(ID_EMP, DT_FROM, DT_TO, CREATE_DATE)
Values(100, TO_DATE('07/01/2008 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('04/30/2010 00:00:00', 'MM/DD/YYYY HH24:MI:SS'),TO_DATE('05/08/2009 14:11:21', 'MM/DD/YYYY HH24:MI:SS'));
I have a function called elig_pay_dates(date p_date), which returns the code for person payment eligibility for a particular date. For paid dates it's 'P' and for unpaid dates it's 'N'.
How can I check this function between two dates for each day. Example : 07/01/2008 to 04/30/2010.
By using this function with select I needs to display the dates when there is a change in status.
I am expecting data in following manner from above logic(this is example):
07/01/2008 --- 07/01/2009 ---'P'
07/02/2009 -- 07/25/2009 ----'N'
07/26/2009 -- 01/01/2010 ---'P'
01/02/2010 -- 01/13/2010 --'N'
01/14/2010 -- 01/18/2010 --'P'
01/19/2010 -- 04/30/2010 -- 'N'
I thought of looping for each day date but that seems to be expensive for online application. Is there any way that I can achieve this requirement with sql query ?
Thanks for your help,Certainly not the best way to code the requirement, but it does achieve the result you are looking for in a fairly quick time
create or replace
function test_ret_paid_unpaid (p_date in date)
return varchar2
is
v_ret varchar2(1);
begin
if ( (p_date between to_date('07/02/2009', 'MM/DD/YYYY') and to_date('07/25/2009', 'MM/DD/YYYY') ) or
(p_date between to_date('01/02/2010', 'MM/DD/YYYY') and to_date('01/13/2010', 'MM/DD/YYYY') ) or
(p_date between to_date('01/19/2010', 'MM/DD/YYYY') and to_date('04/30/2010', 'MM/DD/YYYY') )
then v_ret := 'N';
else
v_ret := 'Y';
end if;
return v_ret;
end;
Wrote file afiedt.buf
1 with get_paid_unpaid as
2 (
3 select dt_from start_date, dt_to end_date, dt_from + level - 1 curr_date, test_ret_paid_unpaid(dt_from + level - 1) paid_unpaid,
4 row_number() over (order by dt_from + level - 1) rn_start,
5 row_number() over (order by dt_from + level - 1 desc) rn_end
6 from test_emp
7 connect by level <= dt_to - dt_from + 1
8 ),
9 get_stop_date as
10 (
11 select start_date init_date, end_date, curr_date, paid_unpaid,
12 case when paid_unpaid != lag(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
13 then curr_date
14 else null
15 end start_date,
16 case when paid_unpaid != lead(paid_unpaid) over (order by curr_date) or rn_start = 1 or rn_end = 1
17 then curr_date
18 else null
19 end stop_date
20 from get_paid_unpaid
21 )
22 select period, paid_unpaid
23 from (
24 select init_date, curr_date, start_date, end_date, stop_date,
25 case when paid_unpaid = lead(paid_unpaid) over (order by curr_date)
26 then nvl(start_date, init_date) || ' - ' || lead(stop_date, 1, end_date) over (order by curr_date)
27 else null
28 end period,
29 paid_unpaid
30 from get_stop_date
31 where stop_date is not null or start_date is not null
32 )
33* where period is not null
12:06:10 SQL> /
PERIOD PAID_UNPAID
01-JUL-08 - 01-JUL-09 Y
02-JUL-09 - 25-JUL-09 N
26-JUL-09 - 01-JAN-10 Y
02-JAN-10 - 13-JAN-10 N
14-JAN-10 - 18-JAN-10 Y
19-JAN-10 - 30-APR-10 N
6 rows selected.
Elapsed: 00:00:00.35 -
Changing base for calculation of Tax
Hi All,
SAP standard delivers 0001 condition type in Tax calculation procedure as base for calculation of Tax. condition type 0001 picks up 0PR0 as base for calcualtion of tax. Can someone tell me how does system picks up 0PR0 as base for calculation of tax as i have to change the base of calculation.
Any hint would be a great help.I think I had the cart before the horse on this problem. The correct way to look at this is what is the best way to get the correct "Net Book Value" and not the correct tax depreciation posting as it never actually gets booked.
By knowing the incorrect Beginning BV, the rate depreciation is applied in year 1 and finally the desired Net BV value at the end of year 1 for tax purposes I am able to calculate the correct Unplanned Depreciation for tax to make everything work out correctly.
correct beginning tax BV $1,200
Beginning Asset Book Value $1,800
depreciation $360 (20% of BV)
Unplanned depreciation $?
Net BV for tax at end of Yr1 $960 ; or 1,200 - (1,200*.2)
With the know values above that makes my unplanned depreciation for Yr 1 to be $480. Year 1 and all following years depreciate correctly after the Unplanned Depreciation is posted.
I am marking this as resolved unless someone sees an error in my thinking.
Thanks,
Jeff -
Need Help on List of Months between Two Dates
Hello everyone,
I have a table which has startdate & enddate, and need a SELECT statement to list all months between these two dates for each given ID.
I did some test, and could not figure out how to get the startdate & enddate from testing table (instead of hard code them) in the select statement.
Could anybody please help on it (Oracle 11gR2),
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. -
Baseline date for payment due date.
Hi,
In FB60 and Miro, Baseline date for calculating due date for payment is taken as default as document date, as per setting in payment terms. But I want to take this date as date of GR/SE. Can we do this. I also want to make it gray and dont want user to change it. Please suggest how to do it.Hi
go through the link answered by me.
Re: Substitution - Baseline Date to be replaced by the Goods Receipt date
the Goods receipt date can be defaulted as Baseline Date.
tell your ABAP consultant to check the BADI and do the necessary.
regards
venkat -
No of Fridays in between two date
Hi all
What is the Qucikest and easy way to retreive the NO of fridyas in betwen two dates
Thanks & Regards
Vivekvivekvm wrote:
Hi all
What is the Qucikest and easy way to retreive the NO of fridyas in betwen two dates
Make sure you test the boundary conditions for any solution you get.
Have you defined exactly what you mean by "in between two dates", for example. do you want to count the end points if one, or both, of them is a friday ?
Regards
Jonathan Lewis
http://jonathanlewis.wordpress.com
http://www.jlcomp.demon.co.uk
To post code, statspack/AWR report, execution plans or trace files, start and end the section with the tag {noformat}{noformat} (lowercase, curly brackets, no spaces) so that the text appears in fixed format.
"Science is more than a body of knowledge; it is a way of thinking"
Carl Sagan -
Comparing dates for equality using API
Hello,
I was wondering if you could help me understand if it is possible for me to compare two dates for equality.
I am looking to only compare the date and the month. So, if I am checking "today" with another objects Date for equality, it obviously fails because the compareTo and the equals method of both Date and Calendar, I think, are comparing even the timestamps.
here is something I wrote for testing, which obviously is of no use
Calendar today = Calendar.getInstance();
Calendar later = Calendar.getInstance();
later.set(Calendar.HOUR, 03);
System.out.println(today.getTime());
System.out.println(later.getTime());
if(today.equals(later)){
System.out.println("BIG BANG");
if(today.compareTo(later)<0)
System.out.println("Today Date is Lesser than my Date");
else if(today.compareTo(later)>0)
System.out.println("Today Date is Greater than my date");
else
System.out.println("Both Dates are equal");
Date today = new Date();
Date myDate = new Date();
myDate.setHours(23);
System.out.println(today);
System.out.println(myDate);
if(today.compareTo(myDate)<0)
System.out.println("Today Date is Lesser than my Date");
else if(today.compareTo(myDate)>0)
System.out.println("Today Date is Greater than my date");
else
System.out.println("Both Dates are equal");
So is then the only way left, is using the simple date formatter and going about things ?package forums;
import java.util.Calendar;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class CalendarExample
private static final DateFormat DF = new SimpleDateFormat("yyyy-MM-dd");
public static void main(String[] args) {
Calendar today = Calendar.getInstance();
Calendar later = Calendar.getInstance();
later.set(Calendar.HOUR, 3);
System.out.println("today="+DF.format(today.getTime()));
System.out.println("later="+DF.format(later.getTime()));
System.out.println("isSameDayAndMonth(today, later) = "+isSameDayAndMonth(today, later));
System.out.println("\n");
Calendar tomorrow = Calendar.getInstance();
tomorrow.set(Calendar.DATE, tomorrow.get(Calendar.DATE)+1);
System.out.println("today="+DF.format(today.getTime()));
System.out.println("tomorrow="+DF.format(tomorrow.getTime()));
System.out.println("isSameDayAndMonth(today, tomorrow) = "+isSameDayAndMonth(today, tomorrow));
System.out.println("\n");
public static boolean isSameDayAndMonth(Calendar a, Calendar b) {
return a.get(Calendar.DATE) == b.get(Calendar.DATE)
&& a.get(Calendar.MONTH) == b.get(Calendar.MONTH)
}You're welcome... Javas standard date libraries leave a lot be desired. I recommend you try Joda, which is [a long standing JSR, which has never gotten up|http://www.theserverside.com/news/thread.tss?thread_id=44248]. -
Date difference calculation - help!
hey people, i've got the below method, i'm trying to calculate the difference between two dates. the calculation is wrong as it is outputing the wrong duration... can anyone help?
public int getDuration(Date startDate,Date endDate)
GregorianCalendar start = new GregorianCalendar();
start.setTime(startDate);
GregorianCalendar end = new GregorianCalendar();
start.setTime(endDate);
long diff = 0L;
if(start.getTime().before(end.getTime()) == true)
diff = end.getTimeInMillis() - start.getTimeInMillis();
diff = diff/(24*60*60*1000);
Long L = new Long(diff);
return L.intValue();
THanks, IanIn the mean time, a couple of stylisitc suggestions:
if(start.getTime().before(end.getTime()) == true)
// == true is redundant and cluttersome
if(start.getTime().before(end.getTime()))
Long L = new Long(diff);
return L.intValue();I'd suggest returning a long, rather than an int. If you insist on returning an int, because you're sure that the number of days will never be more than Integer.MAX_VALUE, then add an assertion that its not.
assert diff <= Integer.MAX_VALUE : diff + " too big";The Long is overkill. If you do have a small enough value, just do return (int)diff; -
The system I am trying to create calculates a number of values based on an input. I need to make the calculations and display the values for an entire production run and for each hour. The only way I know to do this is to create two while loops, one looking at all the values that are received and one looking only at the values for hour long periods.
Any help would be great.
Thanks
RossHWhy do you think that you have to have two loops to accomplish this task? Why not use one loop and accumulate the same data into two data sets based on the two sets of criteria?
-
can i restrict apple mail client from downloading all emails...and allow it to pick a start date for gmail mail to sync? i am flooded with old emails, thousands on them ...eating hard drive space of my macbook pro and un necessary overhead
The genius bar technicians can check your MBP for possible hardware problems and specific software issues that you may have. The diagnosis will be free. Any extensive repairs will not be free.
If you have minor software problems, you essentially will have to deal with them yourself. Examine these two comprehensive documents for possible problem definition and solutions. If you encounter problems that you are unable to cope with, start a new discussion and there will be persons willing to assist you in solving them.
https://discussions.apple.com/docs/DOC-3521
https://discussions.apple.com/docs/DOC-3353
Ciao. -
Hi Dear All,
We have two real time infocubes and two aggregation levels based on these cubes in one multiprovider
first cube1 is like
char1| char2| keyfig_coefficient(single value for each combination of char1 and char2)
same aggregation level1
(we have input query to fill coefficients by one responsible user)
second cube2 is like
char1| char2| keyfig_quantity| keyfig_result
same aggregation level2
Input ready query should be like (for all other users of different org units)
char1|char2|keyfig_coeff| keyfig_quant(for input) | keyfig_result = keyfig_coeff*keyfig_quant(calculated value, should be saved to cube2)
And we don't have pregenerated lines in cube2, users have to add new lines themselves by wad.
Question is, what is the optimal (easiest) way to make calculation and save result data to cube2 where keyfigures for calculation should be used from different infoproviders. I need just a hint.
Appreciate any help.
Nadya.I found decision, agregation levels sould be based on multiprovider, not included.
-
Date Picker Result Used in Query for Flash Chart
Hello,
I'm creating a flash chart using an SQL Query. The query uses two date pickers for the beginning and ending date of the data the query returns. For some reason the substitution string for the data pickers do not work and do not return any data. If I hard wire the start and end date to something like '12/01/2008' and '01/31/2009' the query and the flash chart work just fine. When use the string representing the data pickers (:P65_BEGIN_DATE and :P65_END_DATE) the query does not return any data. Is there some problem using substitution strings in queries for flash charts??
For what it's worth here is the query. (Look near the bottom to see where I reference the data pickers):
SELECT 'Link',
to_char(Day, 'Mon DD'),
((Count("Item Number")-Sum("Devaition"))/Count("Item Number"))*100 as "Precentage"
from
(SELECT
to_date(concat(substr(F4140.PICSDJ, 1, length(F4140.PICSDJ)-3)+1900,
substr(F4140.PICSDJ, length(F4140.PICSDJ)-2,3)), 'yyyyddd') as Day,
F4141.PJLITM AS "Item Number",
sum(F4141.PJTQOH) AS "Sum Qty On Hand",
sum(F4141.PJTQCT) AS "Sum Qty Counted",
(decode(sum(F4141.PJTQOH)-sum(F4141.PJTQCT), 0, 0, 1)) as "Devaition"
FROM F4140 INNER JOIN F4141 ON F4140.PICYNO = F4141.PJCYNO
WHERE (((F4140.PICYCS) In ('40','50')) AND ((F4141.PJCCCD)='1'))
GROUP BY to_date(concat(substr(F4140.PICSDJ, 1, length(F4140.PICSDJ)-3)+1900,
substr(F4140.PICSDJ, length(F4140.PICSDJ)-2,3)), 'yyyyddd'), F4141.PJLITM
HAVING to_date(concat(substr(F4140.PICSDJ, 1, length(F4140.PICSDJ)-3)+1900,
substr(F4140.PICSDJ, length(F4140.PICSDJ)-2,3)), 'yyyyddd')
between to_date(:P65_BEGIN_DATE, 'DD-Mon-YYYY') and to_date(:P65_END_DATE, 'DD-Mon-YYYY') )
group by DayI look at the debug output without changing anything and I am not really sure where the two date pickers are being populated. However I do have defaults set up for each datepicker of:
P65_BEGIN_DATE: to_char(sysdate - 30, 'DD-MON-YYYY')
P65_END_DATE: to_char(sysdate, 'DD-MON-YYYY')
and the dates I would expect show up in the date picker.
Also I created a Computation of Before Header type with the following PL/SQL expression:
to_char(sysdate-180, 'DD-MON-YYYY')
and I see the following output when in debug mode:
0.05: Computation point: BEFORE_HEADER
0.05: ...Perform computation of item: P65_BEGIN_DATE, type=PLSQL_EXPRESSION
0.05: ...Session State: Save "P65_BEGIN_DATE" - saving same value: "03-AUG-2008"
0.05: Processing point: BEFORE_HEADER
So I think the datapickers are being populated but the flash chart is still not working.
Maybe you are looking for
-
How to create a signature in Yosemite for signing documents?
How do I create signatures in Yosemite for signing documents? It used to be in Preview but can't find it now in Yosemite. Thanks.
-
i bought an application in itunes. When i opened the application, it asked me the access key that was sent throught my email address. But when i open my email address, there was no message from apple. how was that? where can i get the access key?
-
I can`t configure database target in GRID CONTROL
hi i have grid control 10.2.0.4 on linux red hat 5. the installation are correct and i discover the first node that have a oracle database. But when i try to configure the database , not appear the configuration page and only give me a error The meta
-
Does Flex 2 provide any services for reporting? I don't know of too many database applications I write for users that don't require a sub set of reports, but reporting over the web is always problematic. We use Crystal Reports, but it comes with its
-
Set Data Roaming to find tower
I recently tried to initiate a call from atop Angel Fire mountain in Angel Fire, New Mexico. The Android Nexus could not find service so I selected Settings> More . . .> Wireless & networks> Mobile networks> Data roaming. To that I received the mes