PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Hi, I am looking all over the internet for a days but Im getting a hard time to find the best tutorial for counting the days for 2 different date fields. I was looking for live counting, I mean for example. I have 3 fields.
datefrom: 1/12/2011
dateto: 1/14/2011
total days: 2 days (readonly)
when the user set the date_from and date_to, total_days field will automatically count when 2 fields are set. is it possible in php? any suggestion or link will be appreciated. thanks guys
function getdate()
{
var one_day=1000*60*60*24;
var fdate = document.getElementById("textFromDate").value;
var tdate = document.getElementById("textToDate").value;
var date1=new Date(fdate);
var date2=new Date(tdate);
if(date1>date2)
{
alert("Not possible");
}
else{
//Calculate difference between the two dates, and convert to days
var Diff=Math.ceil((date2.getTime()-date1.getTime())/one_day);
document.getElementById("textTotalDays").value=Diff+1;
}
}
Hope it will be useful to u..
[Sorry for posting javascript code here]
Have u run that code? what is the result ??. if the result is wrong,rework on that piece of code.i just give u an example for dynamically populating values to the textbox .