Link to home
Start Free TrialLog in
Avatar of ChanderMadhavi
ChanderMadhavi

asked on

Displaying Previous six months/year

Hi
I want to display previous 6 months along with the year in a drop down list. How would I do it?. I can display months of the year But does not work if the month  is february 2004, The drop down just lists jan and February of  2004, While I want the display from september 2003 to Feb 2004.

Thanks

Any help would be helpful.
Thanks
Madhavi
Avatar of Farzad Akbarnejad
Farzad Akbarnejad
Flag of Iran, Islamic Republic of image

Hi,
Please paste your code here.

-FA
Avatar of ChanderMadhavi
ChanderMadhavi

ASKER

The basic code is here
            Dim intX As Integer
            intX = Month(Now)   'Displays month
            While intX <> 0
                ddLstMonth.Items.Add(MonthName(intX))
                intX -= 1
            End While
'This works fine if month is after june. If before june it displays only till jan. I always want to display 6 previous months irrespective of the month of the year. I also just want to restrict the month display to previous 6 months only
Hi

 Use following

         Dim i As Integer = 0
            Dim dt As Date = "4 / 23 / 2004"
            Dim item As String
            For i = 0 To 5
                  If dt.Month - i > 0 Then
                        item = dt.Month - i & dt.Year
                        cmbTest.Items.Add(item)
                  Else
                        item = dt.Month - i + 12 & dt.Year - 1
                        cmbTest.Items.Add(item)
                  End If
            Next

 Here you not get the name of the month but number of month but you can do it for name of the month also

 try it
ASKER CERTIFIED SOLUTION
Avatar of rohanpandya
rohanpandya

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial