Ciao,
ti posto il codice
Codice PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-US" xml:lang="en-US" xmlns="http://www.w3.org/1999/xhtml">
<head>
<script language="JavaScript">
function formatData(getData)
{
d = new Array("Domenica","Lunedi","Martedi'","Mercoledi'","Giovedi'","Venerdi","Sabato");
m = new Array("Gennaio","Febbraio","Marzo","Aprile","Maggio","Giugno","Luglio","Agosto","Settembre","Ottobre","Novembre","Dicembre");
today = getData;
day = today.getDate();
year = today.getYear();
if (year < 2000) year = year + 1900;
var esito = d[today.getDay()]+" "+day+" "+m[today.getMonth()]+" "+year;
return esito;
}
function calcDate(numGiorno)
{
var sommaGiorni = 0;
var appDif = 0;
var miaData = new Date(); // recupero la data di oggi
var dataEsito = new Date();
var mioGiorno = miaData.getDay(); // recupero il giorno di oggi (da 1 a 7)
y = miaData.getHours(); // recupero ora da 1 a 23
y = miaData.getMinutes(); // recupero minuti da 1 a 59
y = miaData.getSeconds(); // recupero secondi da 1 a 59
// condizioni per le quali bisogna ricercare la prossima data
if(mioGiorno != numGiorno)
{
appDif = parseInt(mioGiorno) - parseInt(numGiorno);
//alert('Differenza tra i giorni: ' + appDif);
if (appDif < 0) // oggi è il 5 e cerco il 7
{
//alert('Il giorno che cerchi è dentro la settimana corrente');
sommaGiorni = appDif * -1;
}
else // oggi è il 5 e cerco il 2
{
//alert('Il giorno che cerchi è nella prossima settimana');
sommaGiorni = 7 - appDif;
}
//alert('Giorni da sommare ' + sommaGiorni);
// somma numero di giorni a data di oggi
miaData.setDate(miaData.getDate() + sommaGiorni);
}
dataEsito = formatData(miaData);
return dataEsito;
}
</script>
</head>
<body>
<input type='text' id='txtOggi' style='width:400px' />
<input type='button' onclick="document.getElementById('txtOggi').value=calcDate(1);" value='Ricerca' />
</body>
</html>
Nell'esempio viene ricercato il giorno LUNEDI.
Quello che manca da fare, è mettere a posto le condizioni per le quali bisogna ricercare la prossima data secondo le tue esigenze, ma penso che con il codice che ti ho postato, il più è fatto.
Ciao