Hello, i have this date 01/12/2004. How I make to gain the difference between two dates in days? and to color the background of 3 different cells to second that they are passes 30days 40days or +?
@KorJan 12.2005 — #compare the dates using new Date() constructor
see an example: [code=php] <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <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"> <script language="JavaScript" type="text/JavaScript"> function calculate(f){ var entry = f.elements['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 = newDate-today;//difference in milliseconds dif = Math.ceil(dif/1000/60/60/24);//difference in days f.difD.value = dif + ' days';//assign the difference } </script> </head> <body> <form> <input name="newD" type="text"> Enter the new date in format dd/mm/yyyy<br> <input type="button" onclick="calculate(this.form)" value="Calculate"> <br> <input name="difD" type="text"> difference in days (new date - today) </form> </body> </html> [/code]
<TR bgcolor='lightyellow'><TD id='n30' width='33%' align='center' style='border-right:solid black 1px;border-top:solid black 1px'> +30 days </TD><TD id='n40' width='33%' align='center' style='border-right:solid black 1px;border-top:solid black 1px'> +40 Days </TD><TD id='nX' width='33%' align='center' style='border-top:solid black 1px'> +60 days</TD></TR>