...

View Full Version : Help with years...



terp_in_umcp
01-29-2007, 04:02 PM
Hi there...I am creating a drop-down with years. Now I need to display 10 years starting from this year so 2007, 2008, 2009...2017. So next year the drop down will show 2008, 2009,....2018...I think year(Date+1) is pretty stupid to try...but I did and offcourse it doesnt work:))

<select name=ExpirationYear class=fields>

<option></option>
<option value="Sign In"><%=Year(Date) %></option>
<option value="Sign In From Unpaid break"><%=Year(Date+1) %></option>
<option value="Sign Out For Unpaid break">2009</option>
<option value="Sign Out">2010</option>
<option value="Sign In">2011</option>
<option value="Sign In From Unpaid break">2012</option>
<option value="Sign Out For Unpaid break">2013</option>
<option value="Sign Out">2014</option>
<option value="Sign In">2015</option>
<option value="Sign In From Unpaid break">2016</option>
<option value="Sign Out For Unpaid break">2017</option>
<option value="Sign Out">2018</option>

</select>

Any clues???

terp_in_umcp
01-29-2007, 04:15 PM
Hey there...sorry for posting too soon...looks like i got the answer...silly me...its <%=Year(Date)+2%>

Roelf
01-29-2007, 04:17 PM
uhm, can you just get the value for the current year and then add the neccesary ints? Like:

<select name=ExpirationYear class=fields>

<option></option>
<%
thisyear = Year(Date)
%>
<option value="Sign In"><%=thisyear%></option>
<option value="Sign In From Unpaid break"><%= thisyear + 1 %></option>
<option value="Sign Out For Unpaid break"><%= thisyear + 2 %></option>
<option value="Sign Out"><%= thisyear + 3 %></option>
etc....
</select>

terp_in_umcp
01-29-2007, 04:44 PM
Hey Roefl...that works fine too...much neater in fact:)

angst
01-29-2007, 09:10 PM
or, the correct way would be to use DateAdd()

http://www.w3schools.com/vbscript/func_dateadd.asp

terp_in_umcp
01-29-2007, 09:18 PM
Hey there...still on the drop-down issue, I was trying to insert the drop-down value chosen into the DB...however I am getting an error...is this the right way to do it....

<%
thisyear = Year(Date)
%>

<select name=ExpYear class=fields>

<option></option>
<option value='<%=thisyear %>'[/COLOR[COLOR="Red"]]><%=thisyear %></option>
<option value='<%=thisyear+1 %>'><%=thisyear+1 %></option>

</select>

The Insert statement is a usual insert on the submit page to which this form redirects and and to get this value I am doing '"& Request("EXPYear")&"'

Anything wrong???

angst
01-29-2007, 09:24 PM
can u response.write out the sql statement,
also, what field type is it being inserted into?

terp_in_umcp
01-29-2007, 09:45 PM
Hey there... a <% Response.write(Year(Date)+1)%> gives a correct answer...however as you mentioned the field type of the field is varchar and length is 2, whereas I was trying to insert 2007 or 2008. So I will have to do a right something to get only the last 2 digits...

This seems to work so far...yay:)
<option value='<%=right(Year(Date)+1, 2) %>'><%=thisyear+1 %></option>

Thanks again for your insight angst!!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum