How can I easily build an array using current month as starting point and build 12 buckets where bucket 1 = current month -1 month, bucket 2 = current month -2 month and so on..... Thank you.
Printable View
How can I easily build an array using current month as starting point and build 12 buckets where bucket 1 = current month -1 month, bucket 2 = current month -2 month and so on..... Thank you.
DateTime.Now.Month will give you the current month number. Create a loop for 1 to 12, and keep subtracting (DateTime.Now.AddMonths(-4)). But that is in itself irrelevant - each bucket is simply numbered and can represent the amount to subtract by. Is that all you really need or is there a bigger context to the buckets?
I managed this way, not the best code though..
Code:For i = 0 To myNewMonth.Length - 1
myNewdate = DateTime.Now.AddMonths(-i - 1).ToString
myNewMonth(i) = Month(myNewdate).ToString() & "/" & Year(myNewdate)
Next i
Hey,
I would recommend that you have you a look at the DateTime Members available here:
http://msdn.microsoft.com/en-us/libr...e_members.aspx
There is no reason why you need to do the methods that you are using for Month and Year, these are already available as properties on the DateTime class.
Gary