Solved

convert 2 digit year to 4 digit

Posted on 2006-06-26
4
5,418 Views
Last Modified: 2008-01-09
Hello.

    In the interest of making my application friendly to whiny users, I need to allow a date to be entered as mm/dd/yy AND mm/dd/yyyy.  I have modified my mask to allow this and everything works except my date validation script which REQUIRES that the date be in mm/dd/yyyy format.  

I would like help in creating a function that will ONBLUR check to see if the date is mm/dd/yy and if so add the appropriate 19 or 20 in front of the 2 digit year so that my validation will work properly.  If its already mm/dd/yyyy then do nothing.

Thanks in advance for your help.
Clint...
0
Comment
Question by:clintnash
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 12

Expert Comment

by:netsmithcentral
ID: 16987894
No problem.  Here's the function you would want to register to the onblur event:

function yrChk(){
 var date = this.value;
 var yr = date.split('/')[2];
 if(yr.length==2) yr = (yr>50) ? '19'+yr : '20'+yr;
 date = date.split('/'); date[2] = yr; date.join('/');
 this.value = date;
}
 
0
 
LVL 1

Author Comment

by:clintnash
ID: 16988359
Great, with one small problem.  I attached your script and pass it the control which does change the two digit date to a four digit date, however it produces a strange result.

I enter in 11/11/80 and tab off, it changes the value to

11,11,1980

Any idea on how best to change those commas back to slashes?

thanks for your help,
Clint...
0
 
LVL 12

Accepted Solution

by:
netsmithcentral earned 500 total points
ID: 16988424
Whoops, sorry.  I rejoined the array wrong.  This should fix it:

function yrChk(){
 var date = this.value;
 var yr = date.split('/')[2];
 if(yr.length==2) yr = (yr>50) ? '19'+yr : '20'+yr;
 date = date.split('/'); date[2] = yr; date = date.join('/');
 this.value = date;
}
0
 
LVL 1

Author Comment

by:clintnash
ID: 16988531
That fixed it perfectly.  Its converting to 4 digits and now validating the input.

Thanks so very much for your time today,
Clint...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

I've been trying to accomplish this for a while and it just struck me yesterday how to accomplish this task. I have done searches all over the internet looking for ways to email pages from my applications and finally I have done it!!! Every single s…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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

710 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