Ciao a tutti mi serve un aiutino a modificare questo script. los cript calcola la differenza in giorni tra due date. io vorrei che il formato di inserimento della data non fosse MM/DD/YY ma DD/MM/YY.
grazie a tutti
#

<html xmlns="http://www.w3.org/1999/xhtml" lang="it">
<head>
<SCRIPT LANGUAGE="JavaScript">
<!--
function isValidDate(dateStr) {

// Checks for the following valid date formats:
// MM/DD/YY MM/DD/YYYY MM-DD-YY MM-DD-YYYY

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/; // requires 4 digit year

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert(dateStr + " Formato della data non valido.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Mese: deve essere un valore compreso tra 1 e 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Giorno: deve essere un valore compreso tra 1 e 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Il mese "+month+" non ha 31 giorni!")
return false;
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("Febbraio " + year + " non ha" + day + " giorni!");
return false;
}
}
return true;
}

function dateDiff(dateform) {
date1 = new Date();
date2 = new Date();
diff = new Date();

if (isValidDate(dateform.firstdate.value)) { // Validates first date
date1temp = new Date(dateform.firstdate.value + " ");
date1.setTime(date1temp.getTime());
}
else return false; // otherwise exits

if (isValidDate(dateform.seconddate.value)) { // Validates second date
date2temp = new Date(dateform.seconddate.value + " ");
date2.setTime(date2temp.getTime());
}
else return false; // otherwise exits

// sets difference date to difference of first date and second date

diff.setTime(Math.abs(date1.getTime() - date2.getTime()));

timediff = diff.getTime();

days = Math.floor(timediff / (1000 * 60 * 60 * 24));
dateform.difference.value = days + " giorni, ";

return false; // form should never submit, returns false
}
// End -->
</script>
</head>
<body >
<form onSubmit="return dateDiff(this);">
<table>
<tr><td>
<pre>
Data iniziale: Data: <input type=text name=firstdate value="" size=10 maxlength=10> (formato MM/GG/AAAA)
Data finale: Data: <input type=text name=seconddate value="" size=10 maxlength=10> (formato MM/GG/AAAA)
<input type=submit value="Calcola!">

Differenza:

<input type=text name=difference value="" size=60>
</pre>
</td></tr>
</table>
</form>
</body>
</html>
#