Я хочу, чтобы "входная дата", которая находится в текстовом формате, была в формате даты
я строю вычислитель, который вычисляет неделю и день беременной женщины.
ввод осуществляется в текстовом формате
и я хочу, чтобы это было в формате даты. но когда я меняю его, он не вычисляется
Что я уже пробовал:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<title>Untitled Document
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
function calculate(f){
var entry = f.newD.value.split('/');//splits input value;
if((entry.length<3)||(entry[0].length!=2)||(entry[1].length!=2)||(entry[2].length!=4)||(Number(entry[0]>31))||(Number(entry[1]>12))){//some limitative conditions
alert('Plese input data in format dd/mm/yyyy !');
f.difD.value = '';
return false;
}
y=entry[2]*1;
m=entry[1]*1-1;//sets months to default values i.e Jan = 0; Feb = 1; etc.
d=entry[0]*1;
var newDate = new Date(y,m,d);//sets the new date
var today = new Date();//sets the today date
dif = ((today-newDate)/7)-1;//difference in milliseconds
dif = Math.floor(dif/1000/60/60/24);//difference in days
yamim1 =((((today-newDate)/ 7) / (24 * 3600 * 1000))-dif)*7;
yamim1 = Math.floor(yamim1);
if(dif<0){//if the date is in the past alert('The chosen date is in the past. Please input a valid date!');
f.difD.value = '';
return false;
}
f.difD.value = ' שבוע '+ dif + ' + '+ yamim1 + ' ימים ' ;//assign the difference
}
<br>