Year() function (VB.net) : Date Time « Language Basics « ASP.Net






Year() function (VB.net)

<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub Date_ServerValidation(source As object, E As ServerValidateEventArgs)
    If  IsDate(E.Value) Then
        If  Year(E.Value) = Year(Today) Then
            E.IsValid = True
        Else
            E.IsValid = False
        End If
    Else
        E.IsValid = False
    End If
End Sub
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)

End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Validating for a Date in the Current Year Using the CustomValidator Control</TITLE>
</HEAD>
<form runat="server">
<BR><BR>
Enter a date in the current year:<BR>
<asp:textbox 
    id="txtDate" 
    runat=server 
/>
<asp:customvalidator 
    id="customDate"
    controltovalidate="txtDate"
    onservervalidate="Date_ServerValidation"
    display="Dynamic"
    font-name="Verdana"
    font-bold="True"
    font-size="10pt"
    runat="server">
    You must enter a date in the current year!
</asp:CustomValidator>
<BR><BR>
<asp:button 
    id="butOK"
    text="OK"
    type="Submit"
    onclick="SubmitBtn_Click" 
    runat="server"
/>
</form>
</BODY>
</HTML>
           
       








Related examples in the same category

1.Get Today date (VB.net)
2.Get Time Of a Day (VB.net)
3.DateTime constructor: no parameters (VB.net)
4.DateTime constructor: year, month, day (VB.net)
5.DateTime constructor: year, month, day, hour, minute, second (VB.net)
6.DateTime constructor: milli-second (VB.net)
7.Assign Date and Integer value to asp:textbox without converting (VB.net)
8.Get Hour, Second and Minute from Current time (VB.net)
9.Assign date in form of '#3/6/2003#' to asp:Label (VB.net)
10.Convert Current date to Long Time String and set to asp:Label (VB.net)
11.Convert Current date to Long Date String and set to asp:Label (VB.net)
12.Convert Current date to Short Time String and set to asp:Label (VB.net)
13.Convert Current date to Short Date String and set to asp:Label (VB.net)
14.Time limit validation (C#)
15.new DateTime() (C#)
16.DateTime constructor: year, month, day (C#)
17.DateTime constructor: year, month, day, hour, minute, second (C#)
18.DateTime constructor: milli-seconds (C#)
19.Date Comparison (C#)
20.Convert text in asp textbox into Date (C#)
21.Date calculation: plus 7 days (C#)