Click here to Skip to main content
15,892,746 members
Please Sign up or sign in to vote.
1.33/5 (2 votes)
See more:
Hello,
I have textbox in which we enter date as 020811(string), i want it to be converted to 02/08/2011 and save in database. can anyone please let me know how to do this.Please help me.. I am new to vb...
Posted
Comments
[no name] 2-Aug-11 2:28am    
why dont you use some alternative to this. use datetime picker. if its compulsory then you need to do it manually.
mahalakshmi.p19 2-Aug-11 2:32am    
no i have to enter manually.. i tired all functions....but not getting

 
Share this answer
 
try this code

VB
Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

        If (TextBox1.Text.Length = 2 Or TextBox1.Text.Length = 5) Then
            TextBox1.Text = TextBox1.Text + "/"
            TextBox1.SelectionStart = TextBox1.Text.Length
        End If

        If (TextBox1.Text.Length = 8) Then

            Dim date_str As String = TextBox1.Text
            Dim split_date As String() = date_str.Split("/")
            Dim thisDate As DateTime = New DateTime(Convert.ToInt32("20" + split_date(2)), _
                                                      Convert.ToInt32(split_date(1)), _
                                                      Convert.ToInt32(split_date(0)))
            TextBox1.Text = thisDate.ToString("d/MM/yyyy")
        End If

    End Sub
 
Share this answer
 
try this : Microsoft.VisualBasic.Format(txtSample, "MM/dd/yyyy")
much better if you use a masktextbox and add this code . . .
and code should be like this : Microsoft.VisualBasic.Format(msktextbox, "MM/dd/yyyy")
 
Share this answer
 
v2
i have an DatetimePicker Control and Problame is

if Listview.item(i).subitem(3).text ="" then

Expirydate.value = Format(Now.Date,"MM/yyyy")

else

Expirydate.value = "28/" & Listview.item(i).subitem(3).text


Above code if givint Problame if Error converting String to date in vb.net 2012
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900