How to Calculate number of months between two dates
Hi All,
In one of the fomr developments, I have to calculate the
Number of Days
Number of Months ( Considering Leap Year) provided by the dates, end user enters in the form,
After going thorugh some forum discussion, I have come to know about so many things which were not clear till now.
I have gone through various forums too, some one suggets to make use of FORM CALC and some other JAVA SCRIPT. But the logic i want to build in java script.
The most interesting point is the DATE object is not getting created when i write the below code
var startDate = new DATE(oYear, oMonth, oDay);
I am still not clear, that really the date object gets created in Adobe form If so the why the alert box is getting populated when i write below lines
var oTemp = startDate.getFullYear();
xfa.host.messagebox(oTemp);
So, there are so many unclear things,
If any one can help me by suggesting the approach and how to build the logic in the JavaScript I would be really thankful
Regards
PavanChand
Hi,
ChakravarthyDBA wrote:
Hi
I want number of Sundays between two dates
example
number of Sundays count between '01-04-2013' and '30-04-2013' in one select query I have to include this as sub query in my select statement.Here's one way:
SELECT early_date
, late_date
, ( TRUNC (late_date + 1, 'IW')
- TRUNC (early_date, 'IW')
) / 7 AS sundays
FROM table_x
;This does not depend on your NLS settings.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Point out where the statment above is getting the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002}
Similar Messages
-
How to calculate number of days between two date in Template design?
Hello guys
I have a situation where I have to create a template that returns data, and one of the thing of the existing report is that there is a column that is actually the number of days between start date and end date columns..
So in template, how would I be able to do the same? I have start date and end date columns on the template, now when I created another column using expression like end date - start date and preview the template, I am getting errors saying :
Caused by: oracle.xdo.parser.v2.XPathException: Cannot convert 03/31/2009 to number.
at oracle.xdo.parser.v2.XSLStylesheet.flushErrors(XSLStylesheet.java:1534)
at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:521)
at oracle.xdo.parser.v2.XSLStylesheet.execute(XSLStylesheet.java:489)
at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:271)
at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:155)
at oracle.xdo.parser.v2.XSLProcessor.processXSL(XSLProcessor.java:192)
Please advice
ThanksHi
There is an extension function you can use, from the javadoc:
date_diff
public static long date_diff(java.lang.String format,
java.lang.String fromDate,
java.lang.String toDate,
java.lang.String locStr,
java.lang.String tzID)
Method to get the difference between two dates in the given locale. The dates need to be in "yyyy-MM-dd" format. This function supports only Gregorian calendar.
Parameters:
format - the format to which the difference is required; allowed formats are y (for Year), m(for month), w(for week), d(for day), h(for hour), mi(for minute), s(for seconds) and ms(for milliseconds)
fromDate - the first date
toDate - the second date
locStr - locale string -> lang-Territory
tzID - timezone ID ->http://java.sun.com/j2se/1.4.2/docs/api/java/util/TimeZone.html
Returns:
the difference in dates in the desired format
For example
<?xdoxslt:date_diff(‘d’,’2009-09-14’, ‘2009-09-20’,’en-US’,1)?>
give a result of 6
You can substitute in columns for the dates, just remember the date format required.
Regards
Tim -
How to calculate the hour difference between two dates?
hi all,
how to calculate the hour difference between two dates?
eg i trying this...
((TO_DATE(TO_CHAR(GRNi.reference_date_4,'hh24:mi'),'hh24:mi') -
TO_DATE(TO_CHAR(NVL(GRNi.reference_date_3,SYSDATE),'hh24:mi'),'hh24:mi'))*24)*60 Act_Hr
Reg.
AAKHi
To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following:
select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ),
trunc( sysdate-created ) "Dy",
trunc( mod( (sysdate-created)*24, 24 ) ) "Hr",
trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi",
trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec",
to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ),
sysdate-created "Tdy",
(sysdate-created)*24 "Thr",
(sysdate-created)*24*60 "Tmi",
(sysdate-created)*24*60*60 "Tsec"
from all_users
where rownum < 50
HTH
RangaReddy -
How to count number of sundays between two dates
Hi
I want number of Sundays between two dates
example
number of Sundays count between '01-04-2013' and '30-04-2013' in one select query I have to include this as sub query in my select statement.Hi,
ChakravarthyDBA wrote:
Hi
I want number of Sundays between two dates
example
number of Sundays count between '01-04-2013' and '30-04-2013' in one select query I have to include this as sub query in my select statement.Here's one way:
SELECT early_date
, late_date
, ( TRUNC (late_date + 1, 'IW')
- TRUNC (early_date, 'IW')
) / 7 AS sundays
FROM table_x
;This does not depend on your NLS settings.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only), and also post the results you want from that data.
Point out where the statment above is getting the wrong results, and explain, using specific examples, how you get the right results from the given data in those places.
Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
See the forum FAQ {message:id=9360002} -
How to calculate Number of Hours between 2 dates
Hi,
I have a Column in a table of datatype DATE i.e. Update_Date. Now How do I calculate number of hours passed starting from this date entered in the Update_Date column to SYSDATE. e.g. if the date in column is 2-FEB-2009 and the sysdate is 2/2/2009 2:07:40 AM it should give me 24. How can I get this number of hours.
Update_Date - Sysdate = Number of Hours.
ThanksWhen you subtract two dates in Oracle, you get a difference in terms of days. Just multiply that by 24 to get hours.
SELECT (sysdate - update_date) days,
(sysdate - update_date) * 24 hours
FROM your_tableThat said, it is not obvious how your example works. You state
if the date in column is 2-FEB-2009 and the sysdate is 2/2/2009 2:07:40 AM it should give me 24Since both dates are on February 2, 2009, the only difference is in the time component. If we assume that the time component of the UPDATE_DATE value is midnight since it is not specified, there is a little more than 2 hours of difference between the two dates. How is it that you determine there are 24 hours of difference?
Justin
Edited by: Justin Cave on Feb 2, 2009 10:39 AM -
How to calculate number of days between fixed date and hire date in schema
i want to calculate the number of days between a fixed date en the hire date (infotype 041)
If i read the documentation right, i should use the following command:
HRS=YDXA02
Variable 3 (the x) is the fixed data.
My question is how do i program the variable x?
Let's say the date 01.01.2008
Any help would be welcomeI assume we are talking about PCR for payroll. In this case look at documentation for operation NUM:
OOOOOO
Xnnnnn
X Table
nnnnn Table field
nn Date type 'nn' from the Date Specifications infotype (0041)
Date types are taken from table T548Y.
Your operation would look like:
NUM=Faaesb
F Fixed indicator for deadline calculation
aa Date type: Start date of period to be
calculated; if the date type is not 'nn,'
the second position is left blank.
e Unit, in which the duration is calculated:
T = days
W = week
s End date of period to be calculated:
(blank) End of current payroll period
J End of current calendar year
A Start of current calendar year
B Start of WPBP period
No other specifications are possible.
So it depends on what kind of fixed date you need.
Hope it helps,
Carlos. -
How to Calculate Sum of Difference between two dates
Hi,
I'm using BI Publisher in Siebel CRM.
In RTF template I have the following expression to calculate the Difference between dates
<?xdoxslt:date_diff( 'd' , psfn:totext(CIRGSubmittedDate,"yyyy-MM-dd","MM/dd/yyyy"), psfn:totext(Done,"yyyy-MM-dd","MM/dd/yyyy"), $_XDOLOCALE, $_XDOTIMEZONE)?>
The above expression works for me to calculate the dates.
I need to calculate the Sum of all these dates for a Group.
Want to know the Syntax for Sum function using Date_diff.
Tried the following and didn't work.
<?Sum(xdoxslt:date_diff( 'd' , psfn:totext(CIRGSubmittedDate,"yyyy-MM-dd","MM/dd/yyyy"), psfn:totext(Done,"yyyy-aMM-dd","MM/dd/yyyy"), $_XDOLOCALE, $_XDOTIMEZONE))?>
Not sure what I'm doing wrong here...
Anyone please help...
Thanks
PVHi
To break the diff between 2 dates into days, hours, minutes, sec -- you can use the following:
select to_char( created, 'dd-mon-yyyy hh24:mi:ss' ),
trunc( sysdate-created ) "Dy",
trunc( mod( (sysdate-created)*24, 24 ) ) "Hr",
trunc( mod( (sysdate-created)*24*60, 60 ) ) "Mi",
trunc( mod( (sysdate-created)*24*60*60, 60 ) ) "Sec",
to_char( sysdate, 'dd-mon-yyyy hh24:mi:ss' ),
sysdate-created "Tdy",
(sysdate-created)*24 "Thr",
(sysdate-created)*24*60 "Tmi",
(sysdate-created)*24*60*60 "Tsec"
from all_users
where rownum < 50
HTH
RangaReddy -
I wanted to know how do you calculate the number of days between two dates
i wanted to know how do you calculate the number of days between two dates in java ? i get both the dates from the database. i guess there are many issues like leap year and Febuary having diff no of months ..etc.
thanks..
I solve my problem as
public class MyExample {
public static void main(String a[]) {
String stdate = "2009-03-01";
java.sql.Date currentDate = new java.sql.Date(System.currentTimeMillis());
java.sql.Date preDate = java.sql.Date.valueOf(stdate);
System.out.println(currentDate);
System.out.println(preDate);
// int dateCom = preDate.compareTo(currentDate);
// System.out.println(dateCom);
long diff = currentDate.getTime() - preDate.getTime();
int days = (int) Math.floor(diff / (24 * 60 * 60 * 1000));
System.out.println(days);
} -
How can i get number of days between two dates represented by two dates?
how can i get number of days between two dates represented by two date objects. One is java.sql.Date, the other is java.util.Date?
tej_222 wrote:
But how do I do that conversion. from java.sql.date and java.util.date to calender?
-thanks for the quick response.You may find the following utility code samples useful:
[http://balusc.blogspot.com/2007/09/calendarutil.html]
[http://balusc.blogspot.com/2007/09/dateutil.html]
ganeshmb wrote:
(date1.getTime() - date2.getTime())/(1000*60*60*24) should do.
getTime returns millsecond value of date object and the difference divided by no of milliseconds in a day should fetch you the difference in terms of days.This doesn't respect the DST. Use java.util.Calendar. -
Get number of hours between two dates and two hours using factory calendar
Hello all,
I have the following requirement: I need to calculate the number of hours between two dates and two hours (start date- finish date and start hour-finish hour) or timestamps using a factory calendar. I must program it on CRM environment.
Does anybody know a function module that makes it?
Thanks in advance.
CarmenPlease check function module DURATION_DETERMINE.
- April King -
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 -
Number of sundays between two dates
Hii ,
How can I get number of sundays between two dates...?
Plz help me in this regard
Shoaib rehman*& Report ZEX1
REPORT zex1.
DATA : p_low TYPE d ,
p_high TYPE d .
DATA : gv_scnt TYPE i.
p_low = '20100115' . "feb 1
p_high = '20100228'.
IF p_high > p_low.
PERFORM cal_sundays USING p_low .
WRITE :/ gv_scnt.
ELSE.
* message date combination invalid
ENDIF.
*& Form CAL_SUNDAYS
* text
* --> p1 text
* <-- p2 text
FORM cal_sundays USING p_low ."changing gv_scnt.
DATA : lv_week TYPE scal-week,
lv_sund TYPE d,
lv_mond TYPE d,
lv_scnt TYPE i.
DO .
CALL FUNCTION 'GET_WEEK_INFO_BASED_ON_DATE'
EXPORTING
date = p_low
IMPORTING
week = lv_week
monday = lv_mond
sunday = lv_sund.
IF p_low > p_high.
EXIT.
ELSE.
gv_scnt = gv_scnt + 1.
p_low = lv_sund + 1.
PERFORM cal_sundays USING p_low.
ENDIF.
ENDDO.
ENDFORM. " CAL_SUNDAYS
Execute this and check if this meets ur case . Logic should be something like this .
Br,
Vijay. -
There two ways of finding months between two dates
ROUND((Date1 – Date2) / 365.25 * 12,2) and
ROUND(months_between(date1,date2),2) There is a slight difference between output from these two.
I think the result from the second statement should be more accurate, confirm?
AbhishekAbSHeik wrote:
There two ways of finding months between two dates
ROUND((Date1 – Date2) / 365.25 * 12,2) and
ROUND(months_between(date1,date2),2) There is a slight difference between output from these two.
I think the result from the second statement should be more accurate, confirm?
AbhishekHi Abhishek,
I also agree with this.
Coz 365.25 = (365 + (1/4))
This 0.25 actually the extra year of a Leap Year, distributed equally among 4 years. But, when the 1st formula is evaluated, the calculation might cause difference...
So as far as Oracle is concerned, MONTHS_BETWEEN should be used.
Please rectify me if i'm wrong.
Ranit B. -
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 days between Calendar objects
Hi,
I need to calculate the number of days between two Calendar objects. Here is some sample code:
Calendar now = Calendar.getInstance();
now.set(Calendar.HOUR_OF_DAY, 0);
now.set(Calendar.MINUTE, 0);
now.set(Calendar.SECOND, 0);
now.set(Calendar.MILLISECOND, 0);
// get a calendar that represents a day in the past
Calendar aDayInThePast = getADayInThePast();
aDayInThePast.set(Calendar.HOUR_OF_DAY, 0);
aDayInThePast.set(Calendar.MINUTE, 0);
aDayInThePast.set(Calendar.SECOND, 0);
aDayInThePast.set(Calendar.MILLISECOND, 0);
// how can I calculate the number of days ago this was??
//it would also be useful to get back a negative number if the day is in the futureMy favorite answer so far is reply 15 by Marc__: http://forum.java.sun.com/thread.jspa?threadID=488668&start=15
Maybe you are looking for
-
Print customized report on client printer
I'm evaluating HTMLDB as an option to some MS Access applications we have in place and I have to add I'm a new user with no experience on HTMLDB. One of my applications basically generate a report to be printed on pre-printed forms. For what I've rea
-
Groupwise.wsdl in Visual Studio Web Developer 2010 Express
Hello, I'm trying to add a "Service Reference" in VS Web Developer 2010 Express by importing the groupwise.wsdl file. Everything looks fine when importing the file/adding the reference but when using it several things are missing (e.g. there is no Gr
-
Need transaction code for opening Bex query designer?
Hi ALL, Can anyone help me with the transaction code for opening Bex query designer? Like RRMX for Bex Analyzer similarly i want for Bex query designer. Thanks & Regards Sameer Khan
-
Best Practises for doing Master Scheduling using SNP
Hello Gurus , Can you please suggest the best practises for doing Master Scheduling using SNP . Which engine to use , what would that mean etc Regards, Nick
-
Finding the master user records , how to find the active users
Hi friends, i want master user information, which table consists master user information and also which table consists active users , like address ADRC is the master table like that for users which is the master table . can any one help me urgentl