L
Laser Lips
Hi, I've got a script, which works with dates.
It compares two dates using an operand to test weather the first date
is '<', '>' or '=' to the second date.
Here it is.
function CompareTwoDates(firstDate,secondDate,operator)
{
var tmp;
// ConparisonType eg. <,>,= etc
// first find out if either date is a datetime stamp
if (firstDate.indexOf(":")!=-1)
{
// we assume there is a time portion to remove
tmp=firstDate.split(" ");
firstDate=tmp[0]+" "+tmp[1]+" "+tmp[2]
}
if (secondDate.indexOf(":")!=-1)
{
// we assume there is a time portion to remove
tmp=secondDate.split(" ");
secondDate=tmp[0]+" "+tmp[1]+" "+tmp[2]
}
var fdate=Date.parse(firstDate);
var sdate=Date.parse(secondDate);
var ret=false;
if (isNaN(fdate)) return "Error. First argument is not a Date";
if (isNaN(sdate)) return "Error. Second argument is not a Date";
eval("if (fdate"+operator+"sdate) { ret=true; }");
return ret;
}
USAGE:: alert(CompareTwoDates("01 January 2009","01 January
2010",">"))
Here in the UK it works fine. When I run this on an Italian server I
would expect JavaScript to use it's local settings and use Gennaio
instead of January, but it does not. It appears to continue to use
English Dates.
So my Italians are putting in things like CompareTwoDates("01 Gennaio
2009","01 Gennaio 2010",">") but the function is failing because
javascript does not understand the month Gennaio.
How can I tell JavaScript to use another language?
Thanks,
Graham
It compares two dates using an operand to test weather the first date
is '<', '>' or '=' to the second date.
Here it is.
function CompareTwoDates(firstDate,secondDate,operator)
{
var tmp;
// ConparisonType eg. <,>,= etc
// first find out if either date is a datetime stamp
if (firstDate.indexOf(":")!=-1)
{
// we assume there is a time portion to remove
tmp=firstDate.split(" ");
firstDate=tmp[0]+" "+tmp[1]+" "+tmp[2]
}
if (secondDate.indexOf(":")!=-1)
{
// we assume there is a time portion to remove
tmp=secondDate.split(" ");
secondDate=tmp[0]+" "+tmp[1]+" "+tmp[2]
}
var fdate=Date.parse(firstDate);
var sdate=Date.parse(secondDate);
var ret=false;
if (isNaN(fdate)) return "Error. First argument is not a Date";
if (isNaN(sdate)) return "Error. Second argument is not a Date";
eval("if (fdate"+operator+"sdate) { ret=true; }");
return ret;
}
USAGE:: alert(CompareTwoDates("01 January 2009","01 January
2010",">"))
Here in the UK it works fine. When I run this on an Italian server I
would expect JavaScript to use it's local settings and use Gennaio
instead of January, but it does not. It appears to continue to use
English Dates.
So my Italians are putting in things like CompareTwoDates("01 Gennaio
2009","01 Gennaio 2010",">") but the function is failing because
javascript does not understand the month Gennaio.
How can I tell JavaScript to use another language?
Thanks,
Graham