Search code examples
c#windowsformsmaskedtextbox

Windows forms - textbox that accepts specific timestamp format


How can I add a masked textbox in Windows forms that accepts datetime in the following format:

01/01/1993 12:00 AM


Solution

  • There is a better way to solove this using DateTimePicker

     dateTimePicker1.Format = DateTimePickerFormat.Custom;
     dateTimePicker1.CustomFormat = "MM/dd/yyyy HH:mm";
    

    Best that can be done with MaskedTextbox is by setting following Mask

     maskedTextBox1.Mask = "00/00/0000 00:00 AM"
    

    Then again all of the validations have to be hand written by you.