locked
Display next day in a text box RRS feed

  • Question

  • User810354248 posted

    In my asp.net+VB+SQL web i have a leave request form. In which i have following text boxes to fill details

    Leave From, Leave To , Number of days and On duty date

    when employee fills Leave from date and leave to date

    The number of days gets auto calculated

    I want to display on duty date in a text box named.

    On duty date will be next day of Leave To 

    ASPX

    <asp:TextBox ID="lvefrom" runat="server"></asp:TextBox>

    <asp:TextBox ID="lveto" runat="server" AutoPostBack="True"></asp:TextBox>

    <asp:TextBox ID="nodays" runat="server" AutoPostBack="True" Width="35px" style="text-align: center"></asp:TextBox>

    <asp:TextBox ID="onduty" runat="server"></asp:TextBox>

    VB

    Protected Sub lveto_TextChanged(sender As Object, e As EventArgs) Handles lveto.TextChanged
            Dim DateTo As DateTime
            If Not DateTime.TryParse(lveto.Text, DateTo) Then
                'Invalid date to
            End If
            Dim DateFrom As DateTime
            If Not DateTime.TryParse(lvefrom.Text, DateFrom) Then
                'Invalid date form
            End If
            Dim ts As TimeSpan = DateTo - DateFrom
            nodays.Text = ts.Days + "1"
    
        End Sub

    Monday, July 1, 2019 12:28 PM

Answers

  • User2103319870 posted

    I want to display on duty date in a text box named.

    On duty date will be next day of Leave To 

    You can use AddDays method to add one day to get the next day like below

    Protected Sub lveto_TextChanged(sender As Object, e As EventArgs) Handles lveto.TextChanged
    		Dim DateTo As DateTime
    		If Not DateTime.TryParse(lveto.Text, DateTo) Then
    			'Invalid date to
    		End If
    		Dim DateFrom As DateTime
    		If Not DateTime.TryParse(lvefrom.Text, DateFrom) Then
    			'Invalid date form
    		End If
    		Dim ts As TimeSpan = DateTo - DateFrom
    		nodays.Text = ts.Days + "1"
    		'Add one day to DateTo to get the next day
    		onduty.Text = DateTo.AddDays(1).ToString()
    
    	End Sub

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Monday, July 1, 2019 1:08 PM