Number weeks between two dates which are in same year or different year
Hi,
how to calculate the number of weeks between two dates?
eg. '17-mar-2013' and '27-jun-2013' or '15-jun-2013' and '25-mar-2014'
Thanks in advance.
lukx
A not tested "integer arithmetic" example (to be adjusted to your conceptions if feasible) covering only both dates in the same year and dates in successive years examples.
consider Setting Up a Globalization Support Environment
select case when substr(:start_date,1,4) = substr(:end_date,1,4)
then to_number(to_char(to_date(:end_date,'yyyymmdd'),'iw')) -
to_number(to_char(to_date(:start_date,'yyyymmdd'),'iw'))
when to_number(substr(:end_date,1,4)) - to_number(substr(:start_date,1,4)) = 1
then to_number(to_char(trunc(to_date(:end_date,'yyyymmdd'),'yyyy') - 1,'iw')) -
to_number(to_char(to_date(:start_date,'yyyymmdd'),'iw')) +
to_number(to_char(to_date(:end_date,'yyyymmdd'),'iw')) + 1
end iso_weeks_between
from dual
Regards
Etbin
the following seems to work for iso weeks treated as buckets
with
t as
(select date '2013-03-17' d1,date '2013-06-17' d2 from dual union all
select date '2003-12-31',date '2004-01-01' from dual union all
select date '2004-12-31',date '2005-01-01' from dual union all
select date '2005-12-31',date '2006-01-01' from dual union all
select date '2013-12-29',date '2013-12-30' from dual union all
select date '2016-01-03',date '2016-01-04' from dual union all
select date '2013-06-15',date '2014-03-25' from dual
select d1,
to_number(to_char(d1,'iw')) low_iso_week,
d2,
to_number(to_char(d2,'iw')) high_iso_week,
to_number(to_char(d2,'iw')) - to_number(to_char(d1,'iw')) iso_week_diff,
case when to_number(to_char(d2,'iw')) - to_number(to_char(d1,'iw')) < 0
then to_number(to_char(d2,'iw')) - to_number(to_char(d1,'iw')) +
case when to_char(trunc(d2,'yyyy'),'iw') = '01'
then 52
else to_number(to_char(trunc(d2,'yyyy'),'iw'))
end
else to_number(to_char(d2,'iw')) - to_number(to_char(d1,'iw'))
end iso_weeks_apart
from t
Message was edited by: Etbin
with no Database at hand pencil and paper is too error prone to figure out iso week changes for varioud december - january periods
Similar Messages
-
Create relation between two blocks which are based on different procedure
Hiii
How to create relation between two blocks which are based on different stored procedures in Oracle form??
Pradhyumn Sharmahiii,
I selected the common key deptno in both procedure.
I created a relation between both procedure. but when i compile the form it give an error in ON-CHECK-DELETE-MASTER. My procedure are
==================================
PACKAGE emp_pkg AS
TYPE emprec IS RECORD(
empno asg_emp.empno%type,
ename asg_emp.ename%type,
job asg_emp.job%type,
sal asg_emp.sal%type,
deptno asg_emp.deptno%type);
TYPE emptab IS TABLE OF emprec INDEX BY BINARY_INTEGER;
PROCEDURE empquery(block_data IN OUT emptab, p_deptno IN NUMBER);
end;
====================================
PACKAGE dept_rec IS
type rec is record(dname asg_dept.dname%type,
loc asg_dept.loc%type,
deptno asg_dept.deptno%type);
type deptrec is table of rec index by binary_integer;
PROCEDURE dept_rec1(block1 in out deptrec);
END;
===================================
In ON-CHECK-DELETE-MASTER
CURSOR BLOCK9_cur IS
SELECT 1 FROM dept_rec.dept_rec1 d
WHERE d.DEPTNO = :BLOCK6.DEPTNO;
identifier dept_rec.dept_rec1 must be declared.
Regards
Pradhyumn -
Can Partial Trigger Work between Two Components Which Are in Two Pages?
Scenario: Some output text components in page one while a SelectOneChoice and a InlineFrame are in page two. At first the resource attribute of inlineFrame was set to point to page one. When changing the value of SelectOneChoice, the values of those output text will be expected to change accordingly. I tried to make SelectOneChoice to be the trigger of those output text components, but found that SelectOneChoice can't be seen when attempt to edit the value of PartialTrigger attribute of those output text components. Then I tried to set the ID of SelectOneChoice as the value of the InlineFrame component, but failed getting the wanted result again.
Problem: How to get a partial refreshing effect between two components that are in two different pages? Can partial trigger work in this scenario?
Thanks for your interest!Hi,
Sorry, you can't achieve that the way you're doing it. If you're using 11g, however, you could do that using regions.
Regards,
~ Simon -
Date Difference between two dates which is in String format - Urgent
Hi,
My requirement is
String s1 = "04/24/2008" ; // in "mm/dd/yyyy" format
String s2 = "08/30/2010" ; // in "mm/dd/yyyy" format
Now i want to calculate the number of days between the two Strings(Dates).It's urgent.Please help me.A late entry:
If you want to turn a String into a Date, use SimpleDateFormat.
[Calculating Java dates: Take the time to learn how to create and use dates|http://www.javaworld.com/jw-12-2000/jw-1229-dates.html]
[Formatting a Date Using a Custom Format|http://www.javaalmanac.com/egs/java.text/FormatDate.html]
[Parsing a Date Using a Custom Format|http://www.javaalmanac.com/egs/java.text/ParseDate.html] -
Passing parameter between two portlets which are in two diffrent pages
hi,
This is query regaring passing the parameters from one java portlets to another. Or Receiving parameter from Portlets.
The Secanrio is like :
I have two portlets shown in the two different pages. Now while running the application i want to send the all the data is entered by user in the next page.
1. How to pass the value of all the parameter in the second portlet ?
2. how to name the url of the second page in action of first pageWe need to use portlet events for sending parameters across different pages.
Following documents can give you insight on this :
1. http://portalstudio.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/PDK/ARTICLES/PRIMER.PORTLET.PARAMETERS.EVENTS.HTML
2. http://portalstudio.oracle.com/pls/ops/docs/FOLDER/COMMUNITY/PDK/ARTICLES/DESIGNING.PAGES.USING.PDKJAVA.SAMPLE.EVENT.WEB.PROVIDER.HTML
-AMJAD. -
How can i use cmr between two EJB which are belong to different database?
Perhaps, on the EJB's Entity tabs, in the Deployment settings dialog, you could make sure each bean references a different DB (Change the JNDI name, under Database settings).
However, I don't know this for sure - you may have to use bean-managed persistence. -
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 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
PavanChandHi,
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 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 -
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 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 -
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} -
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 -
How to query the number of working days between two dates
I'm looking for a solution to calculate the number of <i>working</i> days between two dates that I can use in a formated search.
Calculating the total number of days is pretty straight forward but does anyone know how to take into account the settings in the HLD1 (Holiday Dates) table?Hi Eric,
If you are purely looking to exclude holidays defined in the HLD1 table, then you should be able to do it with the following query
NOTE: The following query is an example using OINV table and the fields DOCDATE and DOCDUEDATE for a Particular DOCNUM 'xxx'
If you planning to use within the SAP module then replace DOCDATE and DOCDUEDATE with dynamic field references $[$x.x.x]
SELECT DATEDIFF(DAY,T0.DOCDATE,T0.DOCDUEDATE)-
(SELECT COUNT(STRDATE) FROM HLD1 WHERE STRDATE >= T0.DOCDATE AND STRDATE <= T0.DOCDUEDATE)
FROM OINV T0
WHERE T0.DOCNUM = xxx
Best Wishes
Suda -
SQL to count the number of days between two dates
Does any one have or know how to count the number of days/weeks between 2 dates.
I have thought about using MONTHS_BETWEEN, but do not know how to make it accurate down to one day?
Any suggestions would be appreciated.here are the different queries I came up with to do this, you may want to check it for perticular cases involving Sun and Sat as start and end dates.
select to_number(to_char(to_date('21-JUL-00','dd-mon-yy'), 'ww'))
- to_number(to_char(to_date('10-JUL-00','dd-mon-yy'), 'ww')) from dual;
select (Next_Day(to_date('21-JUL-00','dd-mon-yy')-1, 'Sunday')
- Next_Day(to_date('10-JUL-00','dd-mon-yy')-1, 'Sunday'))/7 from dual;
select (Next_Day(to_date('21-JUL-00','dd-mon-yy')-6, 'Sunday')
- Next_Day(to_date('10-JUL-00','dd-mon-yy')-6, 'Sunday'))/7 from dual;
null
Maybe you are looking for
-
Mail and I Tunes fail to open. Ran Disk repair and did restart. Happened before and then cleared up.
-
SNC 'due quantity is Zero' error in Release prcesse - ASN creation.
Hi~ I am facing problem while creating the ASN' s for the Schedule Line releases. Error message is " Schedule line due quantity is Zero". But due quantity field is not getting populated when I create confirmations and also it is not editable. Status
-
Track iphone with serial number
Can I-Phone be tracked by serial number if the i-phone was reconnected.
-
I downloaded the ios 7 on my iphone 4 and everytime I go to the app store and try to download an app it will tell me i need to read the term and conditions and when i click ok it will take me there and theres nowhere i can click to say i have read th
-
I changed my primary email address because I could not access my old email and now my new iphone asks me to sign in to my old account in order to backup my apps and music from my icloud. when I try to sign in using my password it says it is the wrong