We help IT Professionals succeed at work.

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

482 Views
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?
Comment
Watch Question

Jaime OlivaresSoftware Architect
CERTIFIED EXPERT
Top Expert 2008

Commented:
You should look at .net method GetWeekOfYear ( http://msdn.microsoft.com/en-us/library/system.globalization.calendar.getweekofyear(v=vs.110).aspx )
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

Commented:
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:

=CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(Fields!ODR_DATE.Value,CalendarWeekRule.FirstDay,DayofWeek.Sunday);

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.
Software Architect
CERTIFIED EXPERT
Top Expert 2008
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

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

Thanks!

Author

Commented:
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.
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.