Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2002
    Location
    India
    Posts
    40

    Unanswered: find no of weeks betw two dates

    How can u find the number of weeks between two dates
    Ex:01-jan-2001 and 22-jan-2001..i need no of week from
    these dates...
    Suryadevara

  2. #2
    Join Date
    Dec 2003
    Location
    Noida, India.
    Posts
    171

    Re: find no of weeks betw two dates

    Originally posted by jdbf
    How can u find the number of weeks between two dates
    Ex:01-jan-2001 and 22-jan-2001..i need no of week from
    these dates...
    to_char(date, 'WW') gives week of the year for the date.

    Subtrast this number for the 2 dates
    Oracle can do wonders !

  3. #3
    Join Date
    Jun 2002
    Location
    India
    Posts
    40

    Re: find no of weeks betw two dates

    Thanks for u r reply...that is only used to convert the date to any other formates...but what i need is if user gives two dates , i want to display how weeks are there in between those two dates...

    Ex:01-jan-2004 07-jan-2004, in this date we have one week..like that...

    can any one help on this ASAP
    Suryadevara

  4. #4
    Join Date
    Dec 2003
    Location
    Noida, India.
    Posts
    171

    Re: find no of weeks betw two dates

    Originally posted by jdbf
    Thanks for u r reply...that is only used to convert the date to any other formates...but what i need is if user gives two dates , i want to display how weeks are there in between those two dates...

    Ex:01-jan-2004 07-jan-2004, in this date we have one week..like that...

    can any one help on this ASAP
    What is your defination of start of a week? 31-Dec-03 and 1-Jan-04, are these in same week or 2 different weeks?

    1-jan04 and 5-jan-04 are in same week or different weeks?

    If first week of an yr is taken as first 7 days of the year, then:
    week1 = 1-jan-04 to 7-jan-04
    week2 = 8-jan-04 to 14-jan-04
    and so on.

    According to this, 1jan to 7jan there are 0 weeks and 1jan to 8jan, there is 1 week. This can be obtained using

    Code:
    select
    to_number(to_char(to_date('07-jan-2004','dd-mon-yyyy'), 'WW'))-
    to_number(to_char(to_date('01-jan-2004','dd-mon-yyyy'),'WW'))
    from dual
    Let me know what is your defination of week?
    Oracle can do wonders !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •