Date Calutlations from a DropDownList

P

pvong

Newbie trying to do this in VB.NET

All I want to do is get the value of the last day of the previous year
selected. Example DropDownList

Value Text
191 01/31/2009
190 12/31/2008
189 11/30/2008
188 10/31/2008
187 09/30/2008
186 08/31/2008
185 07/31/2008
184 06/30/2008
183 05/31/2008
182 04/30/2008
181 03/31/2008
180 02/29/2008
179 01/31/2008
178 12/31/2007

What ever date someone picks, I would like it to go to the 12/31 of the
previous year value. If someone picks 01/31/2009, I would like it to give
me the value of "190" because that would be 12/31/08 which is the previous
year. If someone picks 06/30/2008, I would like to return the value 178
which is 12/31 of the previous year.

I know the logic is Dim the selected value and then do some kind of date
calculation so it will tell me how many months to subtract from my Dim
value, but I just don't know how to do that.
Thanks!
 
P

pvong

Mark, that gets me closer but how do you calculate the number of months
between. I ran the example code below and it does give me the correct date
but I need to know the number of month between the selected month and the
12/31/xx.
EndDateDDL is my DropDownList name and my Label1 was just to test to make
sure I get the right 12/31/xx date.
Dim dtmStart As New Date
dtmStart = CType(EndDateDDL.SelectedItem.ToString, Date)
Dim dtmEnd As New DateTime(dtmStart.Year - 1, 12, 31)
Label1.Text = dtmEnd.ToString
 
P

pvong

Mark - I understand. I needed the month difference so I can subtract the
value from the selected month to get the value for the 12/31/xx. Since it's
not an exact science to the do month difference calculation, I just used
your method to do another query and using the new 12/31/xx as a parameter
and got the same result. It's just one more trip back to the db I was
hoping to skip, but not a big deal.

Thanks again!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top