Click here to Skip to main content
14,775,325 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How do yo enter today's date or any date into a masked text box?

My default is ADate.Mask = "##/##/####"

You need to enter it in mask format.


MaskedTextBox1.Text = "00/00/0000"

MaskedTextBox1.Text = "01/06/1998"

MaskedTextBox1.Text = "10/15/2013"

To put the system date into the masked text box use this code

Dim formated_date = My.Computer.Clock.GmtTime.ToShortDateString
If formated_date.Split("/")(0).Length = 1 Then
   formated_date = "0" & formated_date.ToString
End If

If formated_date.Split("/")(1).Length = 1 Then
formated_date = formated_date.Replace("/" & My.Computer.Clock.GmtTime.Day & "/", "/0" & My.Computer.Clock.GmtTime.Day & "/")
End If

MaskedTextBox1.Text = formated_date
Central_IT 25-Jul-13 10:41am
Depending on the system date will be input.
Central_IT 25-Jul-13 10:43am
Depending on the system date will be input automatically
[no name] 25-Jul-13 10:48am
k updated my answer
[no name] 25-Jul-13 10:53am
updated answer again because you will also run into problems if the date is 7/7/2013 so it will make that date 07/07/2013
Central_IT 25-Jul-13 10:56am
Thanks for this code, this will help.
[no name] 25-Jul-13 10:58am
no problem :)
Try this
maskedTextBox1.Text = string.Format("{0:dd/MM/yyyy}", DateTime.Now);

Hope this helps
Central_IT 25-Jul-13 10:56am
Thanks for this code as well, this will help.

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