Periods between two dates .
Hi,
can anyone tell me any function module dat returns the no of periods between two dates .like
if i enter 02.02.2007
05.05.2007
then it shud return periods .
011
012
001
002
003
thnx ,
point will b assigned.
Hi Nishu,
I think what you are looking for in the example below is periods 02, 03,04,05 when you enter dates 02.02.2007 to 05.05.2007.
you have to write a customer exit on posting period.
check the paper below on how to write customer exit and how to derive a variable from another variable.
https://websmp210.sap-ag.de/~sapdownload/011000358700002762582003E/HowToDeriveVariableValue.pdf
Jaya
Similar Messages
-
How to calculate the month difference between two date char. in Query?
Customers would like to see how many months passed between two date type of characteristics (e.g., the month difference between the current date and the scheduled delivery date in the record) and put the result into the column as KF.
We would have to grab the fiscal year/period kind of value and then do the subtraction, e.g., if the current date value is 2/28/2008 and the scheduled delivery date value in the record is 12/01/2007, the correct result should be 2 month difference between these two date values, but could someone here give us the technical light on how to make this happen in query design?
Thanks and we will give you reward points for the correct anwsers!Hi Kevin,
The Badi is RSR_OLAP_BADI.
You can create an implementation using Transaction SE18.
The implementation is per cube and is defined in the filters.
In the Implementation you have the following methods :
1. Define : Here you will provide the Keyfigure you need as a virtual one.
2. Initilialize : Any Init Function you want to do.
3. Compute. This is called per datarecord and here you can cimpute your value.
Hope this helps.
Pralay Ahluwalia -
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 -
How can I calculate the maximum number of days between two dates in a range of dates?
I have a column of dates spanning the couse of a few months. I would like to know if I can calculate the maximum number of days between each row and display the highest number. I currently have another column that calculates the days betwen the rows and I am currently just looking at the totals and highlighting the highest period.
Is this possible? Any help or suggestions are appreciated.
Thank you,
TrevorThis sounds totally possible, Can you post a screen shot of your table to make responding more focused? If you mean you want to:
A) compute the difference (in days) between two date in the same row, then
B) find the max duration (in days)
Here is my take on this problem:
D2 = C2-B2
select D2 and fill down
F1=MAX(D)
to perform the conditional formatting (to highlight the max duration) select column D, then set up conditional formatting as shown in the 1st image -
How to calculate number of sundays and saturdays between two Dates
friends i want to calculate how many Sundays come in two Dates
i have tried following code which is hard coded i have to impliment method which can give me number of Sundays between two Dates
please help me
import java.util.Date;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar ;
import java.util.GregorianCalendar;
public class DateDiffCalculator {
private static final SimpleDateFormat SDF = new SimpleDateFormat("yyyy-MMM-dd");
public DateDiffCalculator() {
public static Date getDate (String date) throws Exception {
//log.debug(" "+date);
return SDF.parse(date);
public static Date getDate (Date date) throws Exception {
// log.debug("date is "+date);
return getDate(SDF.format(date));
public static long getDiffInDays(Date d1,Date d2) {
boolean isdiffGreaterThanYear=false;
long diffInMilliSeconds=d1.getTime()-d2.getTime();
return diffInMilliSeconds/(1000*60*60*24);
public static int getYear(String date) {
//String[] day= {Sun,Mon,Tue,Wed,Thu,Fri,Sat};
Integer year=new Integer(date.substring(0,4));
return year.intValue();
public static int getMonth(String date) {
//String date.substring(5,7);
System.out.println(" "+date.substring(5,8));
String m= date.substring(5,8);
int month=0;
if(m.equalsIgnoreCase("Jan")) {
month=1;
if(m.equalsIgnoreCase("Feb")) {
month=2;
if(m.equalsIgnoreCase("Mar")) {
month=3;
if(m.equalsIgnoreCase("Apr")) {
month=4;
if(m.equalsIgnoreCase("May")) {
month=5;
if(m.equalsIgnoreCase("Jun")) {
month=6;
if(m.equalsIgnoreCase("Jul")) {
month=7;
if(m.equalsIgnoreCase("Aug")) {
month=8;
if(m.equalsIgnoreCase("Sep")) {
month=9;
if(m.equalsIgnoreCase("Oct")) {
month=10;
if(m.equalsIgnoreCase("Nov")) {
month=11;
if(m.equalsIgnoreCase("Dec")) {
month=12;
return month;
public static int getDay(String date) {
Integer day=new Integer(date.substring(9,11));
return day.intValue();
public static int getNumberofSundays(String d1,String d2) throws Exception {
//d1 is leave start date d2 is leave end date
// get object in Date form
Date date1=getDate(d1);
Date date2=getDate(d2);
// now get calender objects from it
GregorianCalendar c1= new GregorianCalendar(getYear(d1),getMonth(d1),getDay(d1));
GregorianCalendar c2= new GregorianCalendar(getYear(d2),getMonth(d2),getDay(d2));
// get period
long leavePeriod = getDiffInDays(date1,date2);
return 12; // it should return number of sundays but we type 12 to perform compilation
public static void main(String[] arg)throws Exception {
System.out.println(" "+getNumberofSundays("2005-Oct-07","2006-Mar-01"));
}thanks now i have modified the get Month Code
as follows
public static int getMonth(String date) {
//String date.substring(5,7);
System.out.println(" "+date.substring(5,8));
String m= date.substring(5,8);
int month=0;
if(m.equalsIgnoreCase("Jan")) {
month=0;
if(m.equalsIgnoreCase("Feb")) {
month=1;
if(m.equalsIgnoreCase("Mar")) {
month=2;
if(m.equalsIgnoreCase("Apr")) {
month=3;
if(m.equalsIgnoreCase("May")) {
month=4;
if(m.equalsIgnoreCase("Jun")) {
month=5;
if(m.equalsIgnoreCase("Jul")) {
month=6;
if(m.equalsIgnoreCase("Aug")) {
month=7;
if(m.equalsIgnoreCase("Sep")) {
month=8;
if(m.equalsIgnoreCase("Oct")) {
month=9;
if(m.equalsIgnoreCase("Nov")) {
month=10;
if(m.equalsIgnoreCase("Dec")) {
month=11;
return month;
but question remains same how to calculate number of Sundays Between 2 Dates -
Difference between two dates: a complete solution
There have been many posts asking how to get the number of days between two dates. There is no method in java like the VB method dateDiff(), and there is only the method date.getTime() which gives you the number of milliseconds since Jan 1 1970, the Epoch. I have not seen a solution that makes use of the fact that there are 86400000 milliseconds per day, only when trying to get the number of days , i.e. multiples of 24 hours between two millisecond points in time.
So what if date1 was Oct 26th 11.30pm and date2 was Oct 27th 12.30am? If you get the millisecond difference, and divide by 86400000, you do not notice that these two times are on separate days, but only one hour apart.
My solution takes account of the modulo (%) function. If you use the date.getTime() method, and use % 86400000 on this number of milliseconds, it will tell you how far (milliseconds) this date is into this day, after 12am. If you subtract this amount from the total number of milliseconds, then divide by 86400000, this will give you the number of days after the Epoch, so you are able to know which day the millisecond time is in. If you want to know the days between two millisecond times, this will tell you, whereas just dividing by 86400000, will not, and may be misleading.
I think this could be incorporated into the Date class easily. There are some problems though, as not every day has 86400000 milliseconds, if you are talking about days when Daylight Saying Time begins or ends. Doing calculations like that will create errors, unless you know whether each date is in Daylight Saving Time or not. Leap years are OK, unless want to work out the number of years from the number of days by dividing by 365, as calculating numbers of days is only done by looking at a 24 hour time period. However where 'leap seconds' have been added, like once every ten years, there may be small errors. This was not included in anyone elses calculations.
So the calculation would go like this:
public class BetterDate extends Date
public int dayDifference(Date d)
long time = this.getTime() ; // gets milliseconds
long timed = d.getTime() ; // gets milliseconds of other date
int days = (time - (time % 86400000))/86400000 ; // number of days
int daysd = (timed - (timed % 86400000))/86400000 ; // number of days of other date
int difference = daysd - days ; // difference in days between two dates
return difference ;
If you want you can use the value (time % 86400000), and modulo this amount with the number of milliseconds in one hour, then subtract the result from the (time % 86400000) and divide by the millliseconds in one hour to give you the number of hours, but there are JDK functions that you can use to get the hour if needed.
This method is not perfect, but for most cases will get you the difference in days between two dates.
JamesHi James,
I tried out your solution, but it seems to fail on dates without times. I tries the difference between 31/03/2002 and 01/04/2002 and the result is 0. I guess it is because the times are assumed to be 00:00 as no times are mentioned and 31st March I believe is the date when DST change will take place this year. If I set the two times as well to a time much later than midnight for example 0600 then I seem to get the right answer.
Joag
There have been many posts asking how to get the
number of days between two dates. There is no method
in java like the VB method dateDiff(), and there is
only the method date.getTime() which gives you the
number of milliseconds since Jan 1 1970, the Epoch. I
have not seen a solution that makes use of the fact
that there are 86400000 milliseconds per day, only
when trying to get the number of days , i.e. multiples
of 24 hours between two millisecond points in time.
So what if date1 was Oct 26th 11.30pm and date2 was
Oct 27th 12.30am? If you get the millisecond
difference, and divide by 86400000, you do not notice
that these two times are on separate days, but only
one hour apart.
My solution takes account of the modulo (%) function.
If you use the date.getTime() method, and use %
86400000 on this number of milliseconds, it will tell
you how far (milliseconds) this date is into this day,
after 12am. If you subtract this amount from the total
number of milliseconds, then divide by 86400000, this
will give you the number of days after the Epoch, so
you are able to know which day the millisecond time is
in. If you want to know the days between two
millisecond times, this will tell you, whereas just
dividing by 86400000, will not, and may be
misleading.
I think this could be incorporated into the Date class
easily. There are some problems though, as not every
day has 86400000 milliseconds, if you are talking
about days when Daylight Saying Time begins or ends.
Doing calculations like that will create errors,
unless you know whether each date is in Daylight
Saving Time or not. Leap years are OK, unless want to
work out the number of years from the number of days
by dividing by 365, as calculating numbers of days is
only done by looking at a 24 hour time period. However
where 'leap seconds' have been added, like once every
ten years, there may be small errors. This was not
included in anyone elses calculations.
So the calculation would go like this:
public class BetterDate extends Date
public int dayDifference(Date d)
long time = this.getTime() ; // gets milliseconds
long timed = d.getTime() ; // gets milliseconds of
other date
int days = (time - (time % 86400000))/86400000 ; //
number of days
int daysd = (timed - (timed % 86400000))/86400000 ; //
number of days of other date
int difference = daysd - days ; // difference in days
between two dates
return difference ;
If you want you can use the value (time % 86400000),
and modulo this amount with the number of milliseconds
in one hour, then subtract the result from the (time %
86400000) and divide by the millliseconds in one hour
to give you the number of hours, but there are JDK
functions that you can use to get the hour if needed.
This method is not perfect, but for most cases will
get you the difference in days between two dates.
James -
Number of occurences between two dates based on a starting date + frequence
I have a starting date in cell A1 and a frequency (in days) in cell B1. In cell C1 I have a date (begin) and in cell C4 I have a later date (end). I need to know how often the event occurs during the time between begin and end dates (inclusive).
For instance, the starting date is january 25th, the frequency is 5. The first date is januari 25th, the second date is februari 12th. The result should be 2 (because given the starting date and frequency of the event, it will occur in februari on day 4 and 9).
I have been looking at some of the statistical functions, but I don't think there is a function for this. Right now I have about 5 formulas to calculate intermediate results, but I'm stuck trying to combine them.
I would be happy with just a pointer in the right direction. For instance, is there a specific name for this kind of calculation?michielvoo wrote:
I have a starting date in cell A1 and a frequency (in days) in cell B1. In cell C1 I have a date (begin) and in cell C4 I have a later date (end). I need to know how often the event occurs during the time between begin and end dates (inclusive).
For instance, the starting date is january 25th, the frequency is 5. The first date is januari 25th, the second date is februari 12th. The result should be 2 (because given the starting date and frequency of the event, it will occur in februari on day 4 and 9).
If the event occurs every five days, the second date will be January 30, and the event will occur four times " during the time between begin and end dates (inclusive)"
I have been looking at some of the statistical functions, but I don't think there is a function for this. Right now I have about 5 formulas to calculate intermediate results, but I'm stuck trying to combine them.
It's not really a statistical calculation, but a simple division to find "How many whole sets of five (days) are there in the days between two dates."
I would be happy with just a pointer in the right direction. For instance, is there a specific name for this kind of calculation?
Two functions and one operation are needed:
DATEDIF() to calculate the number of days between the start and end dates.
Division to determine how many sets of five days there are in that period.
INT() to discard the fractional part of the result.
With the values located as described, this formula (placed in a cell on the same table) will return the number of occurrences not including the first one.
=INT(DATEDIF(C1,C4,"D")/B1)
To include the Start date as one of the occurrences, make this modification:
=INT(DATEDIF(C1,C4,"D")/B1)+1
Regards,
Barry -
Find Exact number of days between two dates
How can get the exact number of days between two dates?
An example of business days calculation in SQL */
/* The algorythm is: */
/* 1) Take the absolute difference between the dates */
/* to_date('&todate') - to_date('&frdate') */
/* 2) Subtract the weekends (number of weeks in the range */
/* TRUNC(to_date('&todate'),'D') = 1st day of week that */
/* end of period is in */
/* TRUNC(to_date('&frdate'),'D') = Last day of week that */
/* start of period is in */
/* So subtracting these two gives the number of days */
/* between the two dates but including all of the days in */
/* the weeks that the dates start and end in. When this */
/* number is divided by 7 it gives the number of weeks. */
/* Multiplying by 2 gives the number of weekend days. */
/* 3) Subtract 1 day if the ending date is on a saturday */
/* DECODE(to_char(to_date('&todate'),'D'),7,-1,0) */
/* --> If the day of the week is saturday (7), returns -1 */
/* 4) Subtract 1 day if the start date is on a sunday */
/* DECODE(to_char(to_date('&frdate'),'D'),1,-1) */
/* --> If the day of the week is sunday (1), returns 1 */
/* 5) Add one day to make the range inclusive (The '1 + ' ) */
/* Author: Kenneth Atkins ([email protected]) */
/* http://www.olywa.net/katkins/oratip */
define frdate = '&1'
define todate = '&2'
set verify off
select
'&frdate' From_Date
,'&todate' To_Date,
1 + to_date('&todate') - to_date('&frdate') -
((TRUNC(to_date('&todate'),'D') - TRUNC(to_date('&frdate'),'D'))/7)*2
+ DECODE(to_char(to_date('&todate'),'D'),7,-1,0)
+ DECODE(to_char(to_date('&frdate'),'D'),1,-1,0) Business_Days
from dual
Here is an example of running the script:
SQL> @busdays 01-AUG-96 15-AUG-96
FROM_DATE TO_DATE BUSINESS_DAYS
01-AUG-96 15-AUG-96 11 -
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!! -
Working days between two date fields and Changing Factory Calendar
Hi,
I have to calculate working days between two date fields excluding the weekends and public holidays for Switzerland.
I have written the routine using factory calender and its working fine except for two problems now:
1. If any one of the date field is empty then teh rsult should be zero.
2. And the below code is working from 1996 but my cleints wants it to work for years before 1996 as well.
I also tried to change the Start date in SCAL for factory calendar but it says enter values between 1995 to 2020.
I am new to ABAP. Please help me how i can achieve these for below code.
DATA: IT_HOLIDAYS type TABLE OF ISCAL_DAY,
IS_HOLIDAYS TYPE ISCAL_DAY.
DATA: T_DATE TYPE SY-DATUM,
P_DATE TYPE SY-DATUM.
DATA : X_DATE(4) TYPE C.
DATA: CNT TYPE I.
REFRESH : IT_HOLIDAYS.
CLEAR : IT_HOLIDAYS.
T_DATE = SOURCE_FIELDS-/BIC/ZCCCHP812.
P_DATE = SOURCE_FIELDS-/BIC/ZCCCHP810.
CALL FUNCTION 'HOLIDAY_GET'
EXPORTING
HOLIDAY_CALENDAR = 'CH'
FACTORY_CALENDAR = 'CH'
DATE_FROM = P_DATE
DATE_TO = T_DATE
TABLES
HOLIDAYS = IT_HOLIDAYS
EXCEPTIONS
FACTORY_CALENDAR_NOT_FOUND = 1
HOLIDAY_CALENDAR_NOT_FOUND = 2
DATE_HAS_INVALID_FORMAT = 3
DATE_INCONSISTENCY = 4
OTHERS = 5.
DESCRIBE TABLE IT_HOLIDAYS LINES CNT.
X_DATE = T_DATE - P_DATE - CNT.
RESULT = X_DATE.
Please help
Regards
Zabina
Edited by: Syed786 on Nov 2, 2011 9:15 AMHi Zabina,
Try this function module 'DURATION_DETERMINE'.
Give the factory calendar and unit as DAY
With regards,
Rajesh -
As to the data type of the data type of the difference between two date type of datas
Hi,
I have a question about the data type of the difference between two date type of datas.
There are two date type of datas as:
SSHIPMENTS.RECEIVEDATETIME
SSHIPMENTS.PROMISEDATETIME
I try to use the following SQL Script in Oracle SQL*Plus as:
SELECT CASE
WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:00:00.000' THEN 'OnTime'
WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:30:00.000' THEN '60-89 Minutes'
ELSE '3+ Hours'
END
FROM SSHIPMENTS;
The error message of "Invalid Number" for the '000 01:30:00.000' happens.
I don't know if the data type of the interval is wrong.
Many Thanks,
CathySELECT CASE
WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss')) < '010000' THEN 'OnTime'
WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss'))< '000 01:30:00.000' THEN '60-89 Minutes'
ELSE '3+ Hours'
END
FROM SSHIPMENTS;
just try it out.. -
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 -
How can i get report between two dates?
Hi
how can i get report between two dates?
for example i want get reports between 20/4/2002 & 27/4/2002.
my table has date column and i can get first date( exam : .... where date:=a and/or ....i don't know this part)
thanks alot.
Regards
The Oracle Reports Team
http://otn.oracle.com/where exam_date between :from_date and :to_date
from_date and to_date are user_parameter -
Difference between two date ,according to office time.
hi,
How can I get diffrence between two date.
If I select from-date 20-03-2012 09:30AM and to-date 20-03-2012 06:30PM then output should be 1 day(as it is office time from 09:30 AM TO 06:30 PM).
ACCORDINGLY If I select from-date 20-03-2012 09:30AM and to-date 21-03-2012 02:00PM then output should be 1.5 day
select 24*(to_date(:P2_TO_DATE,'DD-MM-YYYY HH:MIPM') - to_date(:P2_FROM_DATE,'DD-MM-YYYY HH:MIPM'))"date" from dual;Hello Shirish,
WITH dates AS(
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('20-03-2012 06:30PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('20-03-2012 04:15PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('21-03-2012 02:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 09:30AM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('21-03-2012 12:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 04:30PM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('21-03-2012 02:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 04:30PM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('22-03-2012 02:00PM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
UNION ALL
SELECT TO_DATE ('20-03-2012 04:30PM', 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_DATE ('22-03-2012 10:00AM', 'DD-MM-YYYY HH:MIPM') AS end_date
FROM dual
,times as(
SELECT start_date
,end_date
,TRUNC (end_date - start_date) days
,MOD (end_date - start_date,1) hours
,(start_date - 9.5/24 - TRUNC (start_date))*24 offset_start
,(end_date - 9.5/24 - TRUNC (end_date))*24 offset_end
,(end_date - 9.5/24 - TRUNC (end_date))*24
- (start_date - 9.5/24 - TRUNC (start_date))*24 offset_diff
FROM dates
SELECT TO_CHAR(start_date, 'DD-MM-YYYY HH:MIPM') AS start_date
,TO_CHAR(end_date, 'DD-MM-YYYY HH:MIPM') AS end_date
,days
,ROUND(offset_start,2) offset_start
,ROUND(offset_end,2) offset_end
,ROUND(offset_diff,2) offset_diff
,CASE WHEN offset_diff > 4 THEN
days + 1
WHEN offset_diff > 0 THEN
days + 0.5
WHEN offset_diff = 0 THEN
days
WHEN offset_diff + 9 > 4 THEN
days + 1
ELSE
days + 0.5
END computed_days
FROM timesThe first step (subquery times) computes the full days and the difference between start_date and end_date, compared to the beginning of the office ours (9.5 /24)
The second step takes the days and according to the possible values of the difference adds a half or a full day.
Regards
Marcus
Edited by: Marwim on 19.03.2012 11:23
CASE offset_diff = 0 -
Date difference between two dates
hi All,
i have to right a stored proc to find the difference between two dates.
for example of i give
startdate as 4/1/2015 and enddate 14/1/2015
i should get 1 year , 10 days and 0 months .
i have tried the DateDiff function but it does not calculate the leap year.
please help.DECLARE @from datetime
DECLARE @to datetime
SET @from = '20150104 8:00'
SET @to = '20150114 10:30'
SELECT DATEDIFF(minute,@from, @to) % 60 as Minutes
SELECT (DATEDIFF(minute,@from, @to) / 60) % 24 as Hours
SELECT DATEDIFF(minute,@from, @to) / (60 * 24) as Days
SELECT DATEDIFF(month,@from, @to) as Months
SELECT DATEDIFF(year,@from, @to) as Year
Best Regards,Uri Dimant SQL Server MVP,
http://sqlblog.com/blogs/uri_dimant/
MS SQL optimization: MS SQL Development and Optimization
MS SQL Consulting:
Large scale of database and data cleansing
Remote DBA Services:
Improves MS SQL Database Performance
SQL Server Integration Services:
Business Intelligence
Maybe you are looking for
-
Having trouble setting up Airport Extreme Base Sation
Hi, I'm new to a wireless set up for my Mac. Initially I tried to set up entering various passwords along the way and discovered my cables were not connected correctly - I rectified this and tried again. I was then encouraged to proceed via Bridge mo
-
How to call servlet in action of the Form in jsr 286 portlet
HI, We are using Portlet producer application to create JSR 286 Portle. In the View.jsp of a portlet we need to call a servlet by mention it in the action of the form. WHen I run the only view.jsp page , on form submission the servlet gets called. Bu
-
I purchased a music video and two TV episodes from iTunes. It a long time to download and after it was finished, it disappeared from iTunes. It wasn't found in iTunes or on my iPod. I also downloaded videos from a third party website, got the videos
-
Bridge CS3 no longer previews CR2 Canon
Currently previews of canon raw photos loaded in Bridge do not always show the photo, only the generic icon "CR2", and won't show the photo when slidestrip icon is selected either. It worked on previous downloads, but not currently. I can see the pho
-
Priority based Rserver activation - ACE Load Balancing
Hi, I know certain load balancers which have priority based pool member activation for e.g. the server farm has two rservers. And all the traffic is sent to Rserver1, even though Rserver2 is live. The traffic is forwarded to Rserver2 only when Rserve