Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

convert 2 digit year to 4 digit

Posted on 2006-06-26
4
Medium Priority
?
5,657 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 2000 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

Build and deliver software with DevOps

A digital transformation requires faster time to market, shorter software development lifecycles, and the ability to adapt rapidly to changing customer demands. DevOps provides the solution.

Question has a verified solution.

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

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

661 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