Just started upgrading to VB.Net from VB6.
txtFrom.Text = "1/8"
txtFrom.Text = Format(txtFrom.Text, "dd/MM/yyyy")
This code produces DD/MM/YYYY in the text box.
What should I do to produce 01/08/13?
Just started upgrading to VB.Net from VB6.
txtFrom.Text = "1/8"
txtFrom.Text = Format(txtFrom.Text, "dd/MM/yyyy")
This code produces DD/MM/YYYY in the text box.
What should I do to produce 01/08/13?
Parse the date. Reformat the date.
Dim d As Date = Date.ParseExact(txtFrom.Text, "d/M", CultureInfo.InvariantCulture)
txtFrom.Text = d.ToString("dd/MM/yy")
The format function with "dd/MM/yyyy" will format a date object, not a string. You can convert the string from the textbox to a date using CDate:
txtFrom.Text = Format(CDate(txtFrom.Text), "dd/MM/yyyy")
You might want to use IsDate or a Try-Catch block in case txtFrom.Text is an invalid date.