International Date ToolTip

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.
Who is Participating?
Bob LearnedConnect With a Mentor Commented:
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.

Bob LearnedCommented:
Something like this?

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

dtrickAuthor Commented:
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?
dtrickAuthor Commented:
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.
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.