Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Professional For advanced ASP.NET 1.x coders. Beginning-level questions will be redirected to other forums. NOT for "classic" ASP 3 or the newer ASP.NET 2.0 and 3.5
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 6th, 2003, 10:48 AM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default Week number to a date

I'm trying to create a method that receives a week number and year and returns a date.
Let's say that I pick week number 31 and the year 2003; I expect to receive the day of that Sunday in dd-mon-yyyy format.

I know how to get the week number for a given date but I don't know if there is a built-in method for converting it to a date within the VB.NET or c# framework

Thx
 
Old August 22nd, 2003, 01:30 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

I'm not sure if there is one. I ran into something similar and I typed in the dates manually so to speak. I knew what month I was going to be working in - so if week 50 was picked it would have to be in December likewise, if week 3 was picked it would be january. I used a Select Case statement in Classic ASP to achieve it.
 
Old September 5th, 2003, 06:47 AM
Registered User
 
Join Date: Sep 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I do this by using the following method:



Dim myDATE as date
Dim myYear, myWeek as integer

myDATE = date.parse("1.1." & myYear.ToString)
myDATE = myDATE.date.AddDays(7 * (myWeek-1) - myDATE.DayOfWeek)

Greetings
Volli
 
Old September 5th, 2003, 04:29 PM
Registered User
 
Join Date: Aug 2003
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hummmm. I'll give it a try and let u know.
Thx
Guarddog

 
Old June 23rd, 2004, 02:11 PM
Registered User
 
Join Date: Jun 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I don't know if anyone is still looking to handle this but here is what I have found works, it assumes you want the first day of the
week to be monday (it's for a work schedule).

Code modified for easier display in forum.

DateTime theDay;
DateTime startOfWeek
Double span = Convert.ToDouble(theDay.DayOfWeek)-1)

if(theDay.DayOfWeek != DayOfWeek.Monday){
     startOfWeek = theDay.Subtract(TimeSpan.FromDays(span);
}else{
     startOfWeek = theDay;
}

"Where ever you go, there you are."
 
Old August 17th, 2004, 07:44 PM
Registered User
 
Join Date: Aug 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Dim iWeek as Integer
Dim strYear as String

iWeek = 30
strYear = "2004"

Msgbox DateAdd("ww", iWeek, "1/1/" & strYear)






Similar Threads
Thread Thread Starter Forum Replies Last Post
Week number of the month kpshende SQL Server 2000 4 April 24th, 2006 05:29 PM
Determining a week from current date... flippyn5 PHP Databases 1 December 2nd, 2005 09:01 PM
get the week from the given date Beulah ASP.NET 1.0 and 1.1 Basics 1 September 25th, 2003 11:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.