Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Short date format to long date format

Status
Not open for further replies.

Aasin

Programmer
Aug 5, 2005
7
US
Hello,

Currently I have a asp application that uses javascript to validate the current date. Part of the javascript allows the user to change the current date format which is mm/dd/yyyy to mm/dd/yy. Once the user tabs to the next field then the javascript changes the short date format of what the user entered back to the long date format.
Example: The field display's today's date 02/14/2008. Now the user needs to change the date to 02/11/08. The users are use to entering the short date format. The javascript then converts the short date format to long date. So now the field will display 02/11/2008.

The problem is that now since it has been the year 2008 the javascript changes the short date format of 02/11/08 to 02/11/2000. All the other previous years this javascript has worked but now since it is 2008 the javascript converts 08 to 2000.

Help please. It is really affecting the ability to generate correct analysis.
 
My crystal ball tells me your error is on line 23.


If I told you:
"I'm having a problem multiplying 2 numbers together. I keep getting 56. What am I doing wrong?"
Do you think you could give me the answer?


Perhaps it'd be helpful if you posted the function that's giving you problems.

-kaht

Lisa, if you don't like your job you don't strike. You just go in every day and do it really half-assed. That's the American way. - Homer Simpson

[small]<P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <B> <P> <.</B>[/small]
 
My crystal ball says "Someone forgot to include the radix argument to a call to parseInt".

Never be afraid to share your dreams with the world.
There's nothing the world loves more than the taste of really sweet dreams.

Webflo
 
Here is the function.


function valiDate(inTxt){

// alert(inTxt.value);
var inVal = inTxt.value;
if(inVal == "")
{
return;
}
// If default value is default, don't bother eval-ing it.
////if((inVal == "1/1/1900") || (inVal == "01/1/1900") || (inVal == "1/01/1900") || (inVal == "01/01/1900")){
////return 0;
////}// End if(). commented out 2/17/04

var myArray1 = new Array();
var myArray2 = new Array();
var daysOfMonth = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var daysOfMonth_LY = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
var outStr = "";
var myRegExp1 = /[/]/;
var myRegExp2 = /[0-9]/;
var count = 0;
var i = 0;

// 'A' Check for proper separators.
for(i = 0; i < inVal.length; i++){
if(myRegExp1.test(inVal.charAt(i))){
myArray1[count] = inVal.charAt(i);
count += 1;
}
}
if(myArray1.length != 2){
alert("Use the / between month, day, and year.");
inTxt.value = "";
inTxt.focus();
return 1;
}
// End of 'A' check.

//***********************************************************

// 'B' Load and check values for mm, dd, and yyyy variables.
for(i = 0; i < inVal.length; i++){
if(myRegExp2.test(inVal.charAt(i))){
myArray2[count] = inVal.charAt(i);
count += 1;
}
}
var myI = inVal.indexOf("/");
var myJ = inVal.lastIndexOf("/");
var mm, dd, yyyy;
var outTemp = myArray2.join();
var myRegExp3 = /,/g;
var sysDate = new Date();
var thisYear = sysDate.getFullYear();
outTemp = outTemp.replace(myRegExp3,"");
mm = outTemp.substring(0,parseInt(myI));
dd = outTemp.substring(parseInt(myI),(parseInt(myJ)-1));
yyyy = outTemp.substring((parseInt(myJ)-1));

if(yyyy.length == 2){
yyyy = parseInt(yyyy);
if((yyyy >= 00) && (yyyy <= 50)){
yyyy = 2000 + yyyy;
//alert("value of yyyy = " + yyyy);
} else if((yyyy >= 90) && (yyyy <= 99)){
yyyy = 1900 + yyyy;
//alert("value of yyyy = " + yyyy);
} else {
alert("Year value is out of range.");
inTxt.value = "";
inTxt.focus();
return 1;
}
}

if((mm > 12) || (mm < 1)){
alert("Month value is out of range.");
inTxt.value = "";
inTxt.focus();
return 1;
}// End if().
if((dd > 31) || (dd < 1)){
alert("Day value is out of range.");
inTxt.value = "";
inTxt.focus();
return 1;
}// End if().
if((yyyy > thisYear) || (yyyy < 1989)){
alert("Year value is out of range.");
inTxt.value = "";
inTxt.focus();
return 1;
}// End if().
// End of 'B' check.

//***********************************************************

// 'C' Check for leap year.
if(((isLeapYear(parseInt(yyyy))) && (parseInt(dd) > daysOfMonth_LY[parseInt(mm) - 1])) ||
((!isLeapYear(parseInt(yyyy))) && ( parseInt(dd) > daysOfMonth[parseInt(mm) - 1]))){
alert("Bad date");
inTxt.value = "";
inTxt.focus();
return 1;
}// End if().

inTxt.value = mm + "/" + dd + "/" + yyyy;
var txtDate = new Date(inTxt.value);
var today = new Date();

if(txtDate > today){
alert("Date is greater than today");
inTxt.value = "";
inTxt.focus();
return 1;
}
else{
return 0;
}// End if/else.
// End of 'C' check.
}// End valiDate().



This is the part of the function that isn't working properly....

if(yyyy.length == 2){
yyyy = parseInt(yyyy);
if((yyyy >= 00) && (yyyy <= 50)){
yyyy = 2000 + yyyy;
//alert("value of yyyy = " + yyyy);
} else if((yyyy >= 90) && (yyyy <= 99)){
yyyy = 1900 + yyyy;
//alert("value of yyyy = " + yyyy);
} else {
alert("Year value is out of range.");
inTxt.value = "";
inTxt.focus();
return 1;
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top