Date-format/Local settings

Hi!

I have a field, where the client needs to enter a date. Is there a way for me, to find out the language settings, and then check if the user has used a date-format the corresponds with the settings?

regards,

Nic
LVL 1
JNicAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JNicAuthor Commented:
Thanks nurbek, but these examples does not check the local settings and retrieve the correct date-format from them.
I would like to internationalize this functionality so that no matter if your local date format is YYYY/MM/DD, YY/MM/DD, DD/MM/YY, DD/MM/YYYY or whatever the javascript checks if the entered date fits the local date format.

Thanks again for trying to help me out :-)
0
GwynforWebCommented:
this will give you the language settings (in the code form)

if (navigator.appName == 'Netscape')
  alert(navigator.language);
else
  alert(navigator.browserLanguage);

the region can be further narrowed down by the time diffence from GMT,   date.toGMTString( )

<script>
 d=new Date
 gmt=d.toGMTString( )
 alert(d+'\n'+gmt)
</script>
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

JNicAuthor Commented:
Hi, thanks for the comment! :-)

I was glad to see how I can get the browserlanguage, but my problem with the date format that corresponds with the language is still unsolved.
If javascript doesn't offer a method that returns the correct dateformat for a language, maybe somebody knows where to find information about which dateformat is used in which countries?

Maybe I will have to write a method myself that takes language as a parameter, and returns a dateformat....  - then I have to hard-code all language/dateformat relations.... :-(

Further suggestions?

Thanks again!
0
GwynforWebCommented:
  Trying to identify the formats for a user is going to be close to impossible for instance a Canadian in Ontario will probably be using us-eng (most are too lazy to change the to eng-can) and have a time zone of EST exactly the same as some one from New York, yet one will use dd/mm/yyyy and the other mm/dd/yyyy. The common way of doing it is to force to user to input the date in a given format, eg

YYYY/MM/DD:
<select name="year" size="1">
  <option value="0"></option>
  <option value="2004">2004</option>
  <option value="2003">2003</option>
  <option value="2002">2002</option>
  <option value="2001">2001</option>
  <option value="2000">2000</option>
  <option value="1999">1999</option>
  <option value="1998">1998</option>
  <option value="1997">1997</option>
  <option value="1996">1996</option>
</select>
<select name="month" size="1">
  <option value="0"></option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
  <option value="9">9</option>
  <option value="10">10</option>
  <option value="11">11</option>
  <option value="12">12</option>
</select>
 <select name="day" size="1">
  <option value="0"></option>
  <option value="1">1</option>
  <option value="2">2</option>
  <option value="3">3</option>
  <option value="4">4</option>
  <option value="5">5</option>
  <option value="6">6</option>
  <option value="7">7</option>
  <option value="8">8</option>
  <option value="9">9</option>
  <option value="10">10</option>
  <option value="11">11</option>
  <option value="12">12</option>
  <option value="13">13</option>
  <option value="14">14</option>
  <option value="15">15</option>
  <option value="16">16</option>
  <option value="17">17</option>
  <option value="18">18</option>
  <option value="19">19</option>
  <option value="20">20</option>
  <option value="21">21</option>
  <option value="22">22</option>
  <option value="23">23</option>
  <option value="24">24</option>
  <option value="25">25</option>
  <option value="26">26</option>
  <option value="27">27</option>
  <option value="28">28</option>
  <option value="29">29</option>
  <option value="30">30</option>
  <option value="31">31</option>
</select>
0
JNicAuthor Commented:
OK!??

Well I actually thought that there was exactly ONE dateformat corresponding with ONE browserlanguage!? If this is not the case, then you are right; it will be as good as impossible.

Are you sure that a browserlanguage is not born with a specific unchangable dateformat?

0
nurbekCommented:
Browser language is related with your system language (regional settings)

on the client side it returns clients date format

you had better organize your settings according to your server datetime
suppose that you got one text field (enter all date in one inputbox)
Example : DD/MM/YYYY (format of your server) (3/1/2004) returns "3 January "
               MM/DD/YYYY (format of the client)    (3/1/2004) returns "1 March"

while you are writing the date into database, both are valid date  and returns the same date

in order to aviod this,
you had better use different fields as GwynforWeb  wrote

or you will need to check all client date format
and then (while inserting it into database)  convert client date into server date format



 
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JNicAuthor Commented:
Ok. Thanks!

The last question then (and then I will hand out the points):

How to I check the clients date format?

0
nurbekCommented:
first you have to get the language

ClientLang = Request.ServerVariables("HTTP_ACCEPT_LANGUAGE")

it returns like "en", "de", "ru"

according to them you can define the javascript function that checks right format datetime








0
JNicAuthor Commented:
Thanks to both of you! :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

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.