Click here to Skip to main content
15,943,112 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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 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.

Updated 8-Jul-11 1:11am
Slacker007 8-Jul-11 7:11am    
Edited for some readability and format.

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
    ElseIf (Convert.ToInt16(s2.Split("-")(1)) = Convert.ToInt16(s1.Split("-")(1))) Then
      result=MsgBox(Convert.ToInt16(s2.Split("-")(0)) - Convert.ToInt16(s1.Split("-")(0)))
      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
'Your current value should be
'(cal.GetWeekOfYear(Today, Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday) & "-" & Today.Year)
Share this answer
gani7787 8-Jul-11 7:26am    
Thanks for your help.
But,this year we will have 53 weeks. but, the code always count only 52 weeks.

any other steps..
This is logic, why do u need help.
Share this answer
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.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900