Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2003
    Posts
    1

    Arrow Unanswered: week of the month

    Hi ,

    I dont know Sybase much. Could someone pls help me with this query.?

    input : a date ( Eg. 12.12.2003)

    output : which week that date is of that month ?
    ( 1st , 2nd, 3rd , 4th or 5th ?)

    Thanx in advance,
    Joesach.

  2. #2
    Join Date
    Jan 2003
    Posts
    26

    Re: week of the month

    This is a little tricky since Sybase doesn't do this. All Sybase does is tell you the week of the year. Here's what I came up with:
    select datepart(wk,'12/12/2003') - datepart(wk,dateadd(dd, -(datepart(dd,'12/12/2003') - 1), '12/12/2003')) + 1

    Subtract the week of the date you supplied from the week where the 1st of the month falls and add 1. This assumes that you're talking about the calendar week of the month (ex: the 1st fell on a Monday this month so the first week was the 1st thru the 6th and the 7th would be in the second week).

    Originally posted by joesach
    Hi ,

    I dont know Sybase much. Could someone pls help me with this query.?

    input : a date ( Eg. 12.12.2003)

    output : which week that date is of that month ?
    ( 1st , 2nd, 3rd , 4th or 5th ?)

    Thanx in advance,
    Joesach.

  3. #3
    Join Date
    Feb 2002
    Location
    Willy is on vacation
    Posts
    1,208

    Re: week of the month

    Originally posted by joesach
    input : a date ( Eg. 12.12.2003)

    output : which week that date is of that month ?
    ( 1st , 2nd, 3rd , 4th or 5th ?)
    .
    1> select datepart(cwk,"2003/12/12")
    2> go

    -----------
    50

    By the way, works only in later releases of 12.5.0.3 onwards.

  4. #4
    Join Date
    Jan 2003
    Posts
    26

    Re: week of the month

    That just does calendar week of the year. The original post was asking about week of the month. Is there a function that does that?

    Originally posted by willy_and_the_ci
    1> select datepart(cwk,"2003/12/12")
    2> go

    -----------
    50

    By the way, works only in later releases of 12.5.0.3 onwards.

  5. #5
    Join Date
    Feb 2002
    Location
    Willy is on vacation
    Posts
    1,208

    Re: week of the month

    Originally posted by frankp
    That just does calendar week of the year. The original post was asking about week of the month. Is there a function that does that?
    You can do something like this;

    1> select (datepart(cwk,"2003/12/11") - datepart(cwk,"2003/11/30")) "Week of the
    Month"
    2> go
    Week of the Month
    -----------------
    2

    (1 row affected)
    1>

Posting Permissions

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