Link to home
Start Free TrialLog in
Avatar of dtrick
dtrick

asked on

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 "dd.mm.yyyy" (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.
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Something like this?

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

Bob
Avatar of dtrick
dtrick

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dtrick

ASKER

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.