15,961,678 members
See more:
Hi All,

I have to dropdown. Each dropdown contain week and year values (Ex.1-2006). I want to count the weeks and the count want to display in textboxes in vb.net and also while pageload dropdown should automatically display the current week and year. (Ex.this week is 27th week and 2011 year.)

So both dropdown should display 27-2011 while page load.

How to do this.

1) I want to count no of weeks in between seleted dropdown.(1-2006 to 5-2007) 1 and 5 is the week for the corresponding year.

2) I want to display the current week is by default in the dropdown while page load.

My weeks starts from Monday to sunday.

Thanks in advance for the help.

Regards,
Ganesh.S
Posted
Updated 8-Jul-11 1:11am
v3
Slacker007 8-Jul-11 7:11am
Edited for some readability and format.

## Solution 3

You may be able to use something from Time Period Library for .NET[^]. You would likely have to modify something here, but it could help you along the way.

## Solution 2

This is logic, why do u need help.

## Solution 1

I don't know why I am answering this!! :doh:
Did you even try?

```    Dim result as Integer
Dim s1 As String = "5-2007"
Dim s2 As String = "42-2011"
If (Convert.ToInt16(s2.Split("-")(1)) < Convert.ToInt16(s1.Split("-")(1))) _
OrElse ((Convert.ToInt16(s2.Split("-")(1)) = Convert.ToInt16(s1.Split("-")(1))) And (Convert.ToInt16(s2.Split("-")(0)) <= Convert.ToInt16(s1.Split("-")(0)))) Then
'error
ElseIf (Convert.ToInt16(s2.Split("-")(1)) = Convert.ToInt16(s1.Split("-")(1))) Then
result=MsgBox(Convert.ToInt16(s2.Split("-")(0)) - Convert.ToInt16(s1.Split("-")(0)))
Else
Dim weeks1 As Integer = (52 - Convert.ToInt16(s1.Split("-")(0)))
Dim weeks2 As Integer = (Convert.ToInt16(s2.Split("-")(0)))
result=(52 * (Convert.ToInt16(s2.Split("-")(1)) - Convert.ToInt16(s1.Split("-")(1)) - 1) + weeks1 + weeks2)
End If
'result is the weeks```

```Dim dfi As Globalization.DateTimeFormatInfo = Globalization.DateTimeFormatInfo.CurrentInfo
Dim cal As Globalization.Calendar = dfi.Calendar
'(cal.GetWeekOfYear(Today, Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday) & "-" & Today.Year)
```

gani7787 8-Jul-11 7:26am
Hi,
But,this year we will have 53 weeks. but, the code always count only 52 weeks.

any other steps..