ASP.net VB.net check that date in text box is a certain format

Posted on 2012-08-18
Medium Priority
Last Modified: 2012-08-20

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
Question by:Murray Brown
LVL 26

Assisted Solution

by:Alan Warren
Alan Warren earned 1000 total points
ID: 38308610
Hi murbro,
which flavour datetimepicker are you using?
Most have a format property.

Alan ";0)
LVL 26

Assisted Solution

by:Alan Warren
Alan Warren earned 1000 total points
ID: 38308619
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)
LVL 20

Accepted Solution

informaniac earned 500 total points
ID: 38309003
Please take a look at the Ajax Toolkit Calendar Control.

LVL 25

Assisted Solution

Rouchie earned 500 total points
ID: 38310846
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.

Author Closing Comment

by:Murray Brown
ID: 38310902
Thanks for the help

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month13 days, 11 hours left to enroll

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question