Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Displaying Previous six months/year

Posted on 2004-08-01
4
Medium Priority
?
234 Views
Last Modified: 2010-04-17
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
0
Comment
Question by:ChanderMadhavi
  • 2
4 Comments
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 11691068
Hi,
Please paste your code here.

-FA
0
 

Author Comment

by:ChanderMadhavi
ID: 11691192
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
0
 
LVL 4

Expert Comment

by:rohanpandya
ID: 11691208
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
0
 
LVL 4

Accepted Solution

by:
rohanpandya earned 500 total points
ID: 11691218
following is for the name of the month

  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 = MonthName(dt.Month - i) & dt.Year
                        cmbTest.Items.Add(item)
                  Else
                        item = MonthName(dt.Month - i + 12) & dt.Year - 1
                        cmbTest.Items.Add(item)
                  End If
            Next

      it's work you can select any dt in Date variable dt
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
When you discover the power of the R programming language, you are going to wonder how you ever lived without it! Learn why the language merits a place in your programming arsenal.
Introduction to Processes
Starting up a Project

885 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question