how do I calculte the week of the year calculation in visual studio 2010

Posted on 2014-08-04
Last Modified: 2014-08-06
I need to calculate the week of the year for an SSRS report that I'm writing using Visual Studio 2010.  There are Day, Month and Year functions, but no Week function (like is available in Excel).

So, how do I calculte the week of the year calculation in visual studio 2010?
Question by:makingitbig
    LVL 55

    Expert Comment

    by:Jaime Olivares
    You should look at .net method GetWeekOfYear ( )
    There are many considerations for invoking it, depending on your culture specifics. Here is an example of usage:

    var dt = DateTime.Now;
    CultureInfo.InvariantCulture.Calendar.GetWeekOfYear (dt, CalendarWeekRule.FirstDay, DayOfWeek.Monday);

    Open in new window


    Author Comment

    I'm not familiar with variable declaration within calculated fields in an SSRS dataset; your example looks more like VB code, correct?

    To compensate, I tried the suggestion in this form:


    When I try to preview my report an error message appears essentially saying

    'CultureInfo' is not declared.  It may be inaccessible due to its protection level.

    This occurred even though Intellisense recognized the CultureInfo.InvariantCulture.Calendar.GetWeekofYear method.

    Perhaps you could help me understand how to get the week of year from within an SSRS project.
    LVL 55

    Accepted Solution

    Hi, it may need to be fully qualifies. Please try to add System.Globalization. before CultureInfo

    Author Closing Comment

    adding System.Globalization. before CultureInfo and also before CalendarWeekRule did the trick.


    Author Comment

    by the way, if you have links/recommendations on where I can learn more about all of the methods available (through Visual Studio?), I'd appreciate it.

    Featured Post

    What Security Threats Are You Missing?

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Suggested Solutions

    Title # Comments Views Activity
    has12 challenge 13 52
    abstract class with all non abstract mentods 6 58
    noX challenge 17 54
    Python 2.7 - French characters 6 32
    This article will show, step by step, how to integrate R code into a R Sweave document
    Entering time in Microsoft Access can be difficult. An input mask often bothers users more than helping them and won't catch all typing errors. This article shows how to create a textbox for 24-hour time input with full validation politely catching …
    The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
    The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

    754 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

    24 Experts available now in Live!

    Get 1:1 Help Now