Click here to Skip to main content
15,878,852 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Sir, i have 2 dropdownlist. in first i have months name . and in second i have no of weeks. like:-


XML
<td>
          Month:
              <asp:DropDownList ID="DdlMonth" runat="server">
              <asp:ListItem Value="1">Jan</asp:ListItem>
               <asp:ListItem Value="2">Feb</asp:ListItem>
                <asp:ListItem Value="3">Mar</asp:ListItem>
                 <asp:ListItem Value="4">Apr</asp:ListItem>
                  <asp:ListItem Value="5">May</asp:ListItem>
                   <asp:ListItem Value="6">Jun</asp:ListItem>
                    <asp:ListItem Value="7">Jul</asp:ListItem>
                     <asp:ListItem Value="8">Aug</asp:ListItem>
                      <asp:ListItem Value="9">Sep</asp:ListItem>
                       <asp:ListItem Value="10">Oct</asp:ListItem>
                        <asp:ListItem Value="11">Nov</asp:ListItem>
                         <asp:ListItem Value="12">Dec</asp:ListItem>
              </asp:DropDownList>

              Week:
              <asp:DropDownList ID="DdlWeek" runat="server">
              <asp:ListItem Value="1">1</asp:ListItem>
              <asp:ListItem Value="2">2</asp:ListItem>
              <asp:ListItem Value="3">3</asp:ListItem>
              <asp:ListItem Value="4">4</asp:ListItem>
              <asp:ListItem Value="5">5</asp:ListItem>
              </asp:DropDownList>

             <span style="vertical-align:bottom"> <asp:ImageButton ID="ImageLoad" runat="server" ImageUrl="~/Images/Load.png" Width="30px" Height="30px" /></span>
          </td>




Now i Select in First Dropdown the 5th month it means 'MAY' month. and in Second dropdown i have select "2" week. and then i Click on Imagebutton(ImageLoad). Now i need to display starting dates of that week. it means Starting date of 2nd week of MAY month. How can i get this date by using the value of month and week.
Posted
Updated 5-May-15 19:37pm
v5
Comments
Maciej Los 4-May-15 8:08am    
What have you tried? Where are you stuck?
TCS54321 4-May-15 8:09am    
i have no idea how can i do it..
ZurdoDev 4-May-15 8:19am    
1. Reply to comment so that the user is notified.
2. You say you "need to display second week." What does that mean? No one can help because we don't understand what you want to do nor where you are stuck.
TCS54321 4-May-15 8:22am    
ok.. i have Improve my question..
ZurdoDev 4-May-15 8:27am    
Where? I don't see anything new.

You can get the required information by using a Calendar control or DateTime object and adjusting it forward or back by number of days, weeks, months etc. Check the documentation on MSDN.
 
Share this answer
 
Here: http://stackoverflow.com/questions/662379/calculate-date-from-week-number[^] is an idea. You have to change the code to your needs.

[EDIT]
Your issue is quite interesting, so i decided to write the piece of code to resolve it.

Here is a definition of TDateFromWeek class:
VB
Imports System.Globalization

Public Class TDateFromWeek
    Private firstDayInMonth As Date
    Private dFrom As Date
    Private dTo As Date

    Public Sub New(ByVal yr As Integer, ByVal mh As Integer, ByVal weekno As Integer)
        Dim wn As Integer = 0
        firstDayInMonth = New Date(yr, mh, 1)
        dFrom = firstDayInMonth
        wn = GetWeekOfMonth(dFrom) - GetWeekOfMonth(firstDayInMonth) + 1
        Do While (wn < weekno)
            dFrom = dFrom.AddDays(1)
            wn = GetWeekOfMonth(dFrom) - GetWeekOfMonth(firstDayInMonth) + 1
        Loop
        dTo = dFrom.AddDays(5)

    End Sub

    Public ReadOnly Property DateFrom As Date
        Get
            Return dFrom
        End Get
    End Property

    Public ReadOnly Property DateTo As Date
        Get
            Return dTo
        End Get
    End Property

    Private Function GetWeekOfMonth(ByVal currDate As Date) As Integer
        Dim ci As CultureInfo = CultureInfo.CurrentCulture  'or CultureInfo.CreateSpecificCulture("en-US") 

        Return ci.Calendar.GetWeekOfYear(currDate, CalendarWeekRule.FirstDay, DayOfWeek.Monday)

    End Function

End Class


Usage:
VB
Dim dfw As TDateFromWeek = New TDateFromWeek(2015, 5, 2)
Console.WriteLine("{0} - {1}", dfw.DateFrom.ToString("yyyy-MM-dd"), dfw.DateTo.ToString("yyyy-MM-dd"))
Console.ReadKey()


Result:
2015-05-04 - 2015-05-09
 
Share this answer
 
v2
Comments
TCS54321 6-May-15 1:55am    
Thanku so much Sir.. Its work for me..
Maciej Los 6-May-15 2:02am    
You're very welcome ;)

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