Solved check that date in text box is a certain format

Posted on 2012-08-18
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:murbro
    LVL 26

    Assisted Solution

    by:Alan Warren
    Hi murbro,
    which flavour datetimepicker are you using?
    Most have a format property.

    Alan ";0)
    LVL 26

    Assisted Solution

    by:Alan Warren
    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

    Please take a look at the Ajax Toolkit Calendar Control.
    LVL 25

    Assisted Solution

    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

    Thanks for the help

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Suggested Solutions

    In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
    A quick way to get a menu to work on our website, is using the Menu control and assign it to a web.sitemap using SiteMapDataSource. Example of web.sitemap file: (CODE) Sample code to add to the page menu: (CODE) Running the application, we wi…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now