p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


  Return to Index  

proasp_howto thread: Give date of first day of the week with givven weeknumber


Message #1 by "Bart Beekhuizen" <bart@d...> on Thu, 2 Aug 2001 14:01:50 +0200
Bart,

Out of curiosity, What language is the days and months in?

Thanks,
Yehuda

-----Original Message-----
From: bart@d... [mailto:bart@d...]
Sent: Friday, August 03, 2001 7:40 AM
To: Pro ASP HowTo
Subject: [proasp_howto] Re: Give date of first day of the week with
givven weeknumber


--------------------------------------------------------
I was a little too fast with asking for help. I've tryed for a couple of
hours and got the exact function I wanted.
Give the week, the year and the day(0=3Dmonday, 1=3Dtuesday etc) if you 
want to know the exact date.
But thanks for your reply, I appreciate it.

Function DatumDag(week, jaar, dag)
	Dim icounter, dtWeekBegan, dtIterate,arrWeekdays
	arrWeekDays = Array
("", "Zondag", "Maandag", "Dinsdag", "Woensdag", "Donderdag", "Vrijdag",
"Zaterdag")
	arrMaanden = Array
("", "januari", "februari", "maart", "april", "mei", "juni", "juli",
"augus tus", "september", "oktober", "november", "december")

	dtWeekBegan = DateAdd("d", 2 - WeekDay(Date), Date)
	weeknu = DatePart("ww", Date)
	
	maandag_week = DateAdd("ww", (week - weeknu), dtWeekBegan)

	dag = DateAdd("d", dag, maandag_week)
	DatumDag = arrWeekDays(Weekday(dag)) & " " & Day(dag) & " " &
arrMaanden(Month(dag)) & " " & jaar

End Function

----------------------------------------------------------------
> If you have the year, then you can modify this to return a date
>
> Use DateAdd to return a date from the known week of the year.
>
> dateadd(interval, number, date)
>
> Add the known weeknumber to the first day of the known year.
>
> NewDate  = dateadd("ww",28,#1/1/01#)
>
> NewDate now equals '7/16/2001'
>
> Please notice in this case, NewDate just happens to be Monday,
> 7/16/2001. DateAdd added (28*7) days to 1/1/01. 1/1/01 just happened
> to be a Monday.
>
> Now that you have the NewDate, you can derive the MONDAY of the week
> represented by 7/16/2001
>
> Here's the function
> Also, bear in Mind that I am using the Julian Calendar where Sunday is
> first day of week.
> The code should act differently if your locale settings are different.

> Modify accordingly.
>
> Function FindMonday( intWeek,intYear)
> dim NewDate, DayOfWeek
>
> NewDate =3D DateAdd("ww",intWeek,"01/01/" & CStr(intYear))
>
> DayOfWeek = WeekDay(NewDate)
> Select Case DayOfWeek
> Case 1 'Sunday
>       FindMonday = DateAdd("d",1,NewDate)
> Case 2 ' Monday
>       FindMonday = NewDate
> Case 3 'Tueday
>       FindMonday = DateDiff("d",1,NewDate)
> Case 4 'Wednesday
>       FindMonday = DateDiff("d",2,NewDate)
> Case 5 'Thursday
>       FindMonday = DateDiff("d",3,NewDate)
> Case 6 'Friday
>       FindMonday = DateDiff("d",4,NewDate)
> Case 7 'Saturday
>       FindMonday = DateDiff("d",5,NewDate)
> end select
> end function
>
> Hope this helps
>
> Dallas
>
> ----- Original Message -----
> From: "Bart Beekhuizen" <bart@d...>
> To: "Pro ASP HowTo" <proasp_howto@p...>
> Sent: Thursday, August 02, 2001 8:01 AM
> Subject: [proasp_howto] Give date of first day of the week with givven
> weeknumber
>
> > Is there a way to return the date with a given weeknumber?
> > Example: weeknumber is 28, year is 2001
> > I want to have as a result, the date of the Monday of this week:
> > 07/09/2001 I've managed to get the day of the year:
> >
> > <%
> > week jaar datum datumdag Response.Write datumdag
> > 'It returns 190, that is the day of the year
> > %>
> >
> > Thanks,
> >
> > Bart Beekhuizen
> > bart@d...


  Return to Index