asp: label.text to week of year?

Posted on 2009-12-24
Last Modified: 2013-11-07
I need to get the week of year into SQL.
Everything I have tried generates runtime or compile errors.
How can I do this:

I have asp:

Label2.Text = string of a date of the year

SQL: " ... DATEPART(wk, CONVERT(datetime,@Label,101) ) "

               <asp:ControlParameter Name="Label"  ControlID="Label2"  PropertyName="Text" />
Question by:pillmill
    LVL 4

    Expert Comment

    This one works:
    DECLARE @date datetime
    SET @date = '20090301'

    SELECT CASE WHEN @date NOT BETWEEN DATEADD(day, -DATEPART(dw, (DATEADD(year, DATEDIFF(year, 0, @date) +1, 0))), (DATEADD(year, DATEDIFF(year, 0, @date) +1, 0))) +1 AND DATEADD(year, DATEDIFF(year, 0, @date) +1, 0) -1 THEN DATENAME(week, @date)
    ELSE 1 END

    LVL 29

    Expert Comment

    by:Kumaraswamy R
    LVL 6

    Expert Comment

    use this

    Dim weekNum As Integer = DatePart(DateInterval.WeekOfYear, Date.Now, Microsoft.VisualBasic.FirstDayOfWeek.Monday)
    LVL 6

    Accepted Solution

    or in C#

    public static int GetWeekNumber(DateTime dtPassed)
            CultureInfo ciCurr = CultureInfo.CurrentCulture;
            int weekNum = ciCurr.Calendar.GetWeekOfYear(dtPassed, CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
           return weekNum;


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    In my previous two articles we discussed Binary Serialization ( and XML Serialization ( In this article we will try to know more about SOAP (Simple Object Acces…
    This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
    Hi everyone! This is Experts Exchange customer support.  This quick video will show you how to change your primary email address.  If you have any questions, then please Write a Comment below!
    Sending a Secure fax is easy with eFax Corporate ( First, Just open a new email message.  In the To field, type your recipient's fax number You can even send a secure international fax — just include t…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now