Click here to Skip to main content
15,890,399 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 = "##/##/####"
Posted

You need to enter it in mask format.

Examples:


VB
MaskedTextBox1.Text = "00/00/0000"

VB
MaskedTextBox1.Text = "01/06/1998"

VB
MaskedTextBox1.Text = "10/15/2013"


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

VB
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
 
Share this answer
 
v3
Comments
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.
Try this
C#
maskedTextBox1.Text = string.Format("{0:dd/MM/yyyy}", DateTime.Now);

Hope this helps
 
Share this answer
 
Comments
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