International Date ToolTip

Posted on 2007-07-24
Last Modified: 2008-02-01
I have a page that accepts a date in a TextBox. I have a CompareValidator pointed to this TextBox that ensures the value inside the TextBox is a date.

So now I would like to inform the user what format they should enter their date as. So for a site that is operating in the US I should be able to tell them that the format is something like "mm/dd/yyyy". OR if they are in Australia the format should be "dd/mm/yyyy". Or in Germany "" (or something like that).

The key for this is that I don't want to hard-code the value. I also don't want to use a conditional statement like:
IF (US) THEN "mm/dd/yyyy" ELSE "dd/mm/yyyy"

I am wondering if there is some property on the "CurrentCulture" or "CurrentUICulture" objects that would facilitate the automatic generation of a valid short date.
Question by:dtrick
    LVL 96

    Expert Comment

    by:Bob Learned
    Something like this?

            string format = System.Threading.Thread.CurrentThread.CurrentCulture.DateTimeFormat.ShortDatePattern;


    Author Comment

    That gets me close to what I'm looking for. That provided me with the string "M/d/yyyy". Technically speaking that is 'proper' format. Unfortunately for me I'm looking for the more user recognizable format of "mm/dd/yyyy". Any thoughts on achieving this?
    LVL 96

    Accepted Solution

    Unfortunately, there isn't an easy way.  With the en-US (United States) culture the short date format is M/d/yyyy, and with en-GB (Great Britain), the short date format is dd/MM/yyyy, as expected.  You could fudgte it and make M/d/yyyy equal to MM/dd/yyyy if you wanted.


    Author Comment

    I think you are right in that I'll probably need to fudge it. I'm thinking the best way for me to proceed is to manipulate the value that comes out of the 'ShortDatePattern'. I'll probably run a RegEx on the string to find any non-repeating 'M' and replace it with 'MM'. Then do the same for 'D'. Lastly, I'd run a toLower() on the string. Its more computation than I like, but that is the price you pay for being dynamic.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    IntroductionWhile developing web applications, a single page might contain many regions and each region might contain many number of controls with the capability to perform  postback. Many times you might need to perform some action on an ASP.NET po…
    Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    how to add IIS SMTP to handle application/Scanner relays into office 365.

    761 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

    7 Experts available now in Live!

    Get 1:1 Help Now