Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

How do I get a date from the week number and year?

Posted on 2008-11-14
4
Medium Priority
?
419 Views
Last Modified: 2012-05-05
I need to get the date of the first day in a given week (Sunday is the 1st day of the week). I'm using VB.Net in Visual Studio 2005. For example, if I pass it week# 46 and the year 2008 I should get the date of Sunday, Nov. 9, 2008.
0
Comment
Question by:rkeith27
  • 2
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Christopher Kile earned 500 total points
ID: 22961654
This is problematic.  How do you want to handle week 1 if the year doesn't begin on a Sunday?
I'll assume that the first week of the year begins on the Sunday of that week.

Function DateOfThisWeek(ByVal weekNumber As Integer, ByVal year As Integer)
    Dim firstSunday As DateTime = DateTime.Parse(year & "/01/01").AddDays(-(DateTime.Parse(year & "/01/01").DayOfWeek))
    Return firstSunday.AddDays((weekNumber - 1) * 7.0)
End Function
0
 

Author Closing Comment

by:rkeith27
ID: 31516844
Great!
0
 

Author Comment

by:rkeith27
ID: 22961799
I'd handle the first week as the first 4 day week as week 1 with the start day of the week as Sunday.
0
 
LVL 23

Expert Comment

by:Christopher Kile
ID: 22961862
Yup, that's what I thought would work best.  I remember wrangling about it, though, more than once in different jobs.  Everyone has an opinion... :D
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…

580 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