check that date in text box is a certain format


I use the following code to add a date to a text box. I want to be able to check that the format is always "dd MMMM yyyy" when the user manually changes the text box. How do I do this?

    Protected Sub InvoiceDate_DateTimePicker_SelectionChanged(sender As Object, e As EventArgs) Handles InvoiceDate_DateTimePicker.SelectionChanged
        Dim sTransactionDate As String = Me.InvoiceDate_DateTimePicker.SelectedDate.ToString("dd MMMM yyyy")
        Me.txtDatePaid.Text = sTransactionDate
    End Sub
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAsked:
Who is Participating?
Obadiah ChristopherConnect With a Mentor Commented:
Please take a look at the Ajax Toolkit Calendar Control.
Alan WarrenConnect With a Mentor Applications DeveloperCommented:
Hi murbro,
which flavour datetimepicker are you using?
Most have a format property.

Alan ";0)
Alan WarrenConnect With a Mentor Applications DeveloperCommented:
Hi murbro,
the following returns 29 August 2008
    Dim date1 As Date = #8/29/2008 7:27:15 PM#

    Console.WriteLine(date1.ToString("dd MMMM yyyy", System.Globalization.CultureInfo.CreateSpecificCulture("en-US")))
    ' Displays 29 August 2008

Open in new window

Alan ";0)
RouchieConnect With a Mentor Commented:
What is the reason that you need to force dates to the "dd MMMM yyyy" format?

You are actually embarking on a difficult task that is making your application less usuable and harder to debug - because a huge portion of the world will not read or write dates in that format.  ASP.NET intelligently displays dates based on the user's browser preference, so you should really leave this logic in place if possible.
Murray BrownMicrosoft Cloud Azure/Excel Solution DeveloperAuthor Commented:
Thanks for the help
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.