[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Date-format/Local settings

Posted on 2004-11-10
10
Medium Priority
?
258 Views
Last Modified: 2008-03-10
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
0
Comment
Question by:JNic
  • 5
  • 3
  • 2
10 Comments
 
LVL 13

Expert Comment

by:nurbek
ID: 12544254
0
 
LVL 1

Author Comment

by:JNic
ID: 12544342
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
 
LVL 31

Assisted Solution

by:GwynforWeb
GwynforWeb earned 375 total points
ID: 12545495
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:JNic
ID: 12549341
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
 
LVL 31

Expert Comment

by:GwynforWeb
ID: 12550653
  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
 
LVL 1

Author Comment

by:JNic
ID: 12552803
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
 
LVL 13

Accepted Solution

by:
nurbek earned 375 total points
ID: 12552856
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
 
LVL 1

Author Comment

by:JNic
ID: 12553002
Ok. Thanks!

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

How to I check the clients date format?

0
 
LVL 13

Expert Comment

by:nurbek
ID: 12553130
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
 
LVL 1

Author Comment

by:JNic
ID: 12554277
Thanks to both of you! :-)
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

867 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