need help plz

  • Hi..........

    How do i write a code to find the weeknumber in a given month for the given date

    if the date is 06/10/2005 it should give as week 2 jun 2005

     

  • This may be what you are looking for:


    Select convert(char(10),getdate(),110) [current_date],

    datediff(ww,dateadd(M, datediff(M, 0, getdate()), 0),getdate()) + 1 as [week_number]

    current_date week_number

    ------------ -----------

    06-10-2005   2


    This code gets the number of weeks + 1 from the beginning of the month, 6/10/2005 in this case.  You can test by substituting other dates for getdate().

    All due credit to Frank Kalis.  These two articles go a long way in explaining Sql Server dates and how to work with them.

    http://www.karaszi.com/SQLServer/info_datetime.asp

    http://www.sql-server-performance.com/fk_datetime.asp

  • hey..........thank u very much. this is what i wanted. and the two sites are very useful. really apprecite for ur help

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply