|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
I need to be able to calculate the date of every Monday depending on what week number/year it is.
For example is it possible to calculate the date (e.g. 20/10/2003) of a given day (e.g. Monday) when you only know the week number (e.g. 43) and the year (e.g. 2003) If anyone can point me in the right direction, your help would be greatly appreciated. Many thanks in advance Jon |
|
#2
|
|||
|
|||
|
In Visual Basic Net you can get the day of the week for a date by declaring a variable as type "Date" and getting the property "DayOfWeek".
I do not know how this works in earlier versions of VB but I am sure it can be done. You should now be able to work out an algorithm to calculate the start of week for any given date by going back the required number of days. |
|
#3
|
|||
|
|||
|
I have just had another look at the problem using VB5.
If you use the Weekday function you can get the day of the week for the first day of the year for any given year. In the following sample I have assumed that week one is the week beginning on a Monday which contains 1st January of that year. This means that in most cases week one begins in the previous year. Private Sub cmdFindStartOfWeek_Click() Dim TempDate As Date TempDate = CDate("01/01/" & txtYear) - WeekDay("01/01/" & txtYear, vbMonday) + 1 TempDate = TempDate + 7 * (txtWeekNo - 1) txtStartOfWeek = TempDate End Sub For clarity I have broken it up into 2 parts. First, find the date of the start of the first week of the year. Then find the date of the relavent week. You can use the following to find the Monday prior to a given date. TempDate = txtDate - WeekDay(txtDate,vbMonday) + 1 |
![]() |
| Viewing: ASP Free Forums > Programming > Visual Basic Programming > Calculating a date from week number & year |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|
|