• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 414
  • Last Modified:

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.
0
dtrick
Asked:
dtrick
  • 2
  • 2
1 Solution
 
Bob LearnedCommented:
Something like this?

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

Bob
0
 
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?
0
 
Bob LearnedCommented:
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
0
 
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.
0

Featured Post

Microsoft Certification Exam 74-409

VeeamĀ® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now