i want to find the date differnce between two dates.how can i do that .please suggest,i am getting the differnce but with date
giving the differnce 24, but it should give 25. i am using,first creating the object of Date Class with the given date and then find the diffrence betwen the start date and End Date object and then divided this value with one day milliseconds.
Thanks forypour quick reply, im using this code ,
var strDateObj:Date = new Date(2012,5,8);
var endDateObj:Date = new Date(2012,6,1);
var nDiffDays = Math.floor((endDateObj - strDateObj)/86400000);
// output is 24 but it should show 25
So please suggets where i am wrong
Sorry for giving wrong output boyle, but its giving the 23 days when start date (2012,5,8) and End date is(2012,5,31)
and also giving the same output when i use start date (2012,5,8) and End date is(2012,6,1).
you realise that months are 0-indexed? new Date(2012, 5, 8) is the 8th of June not the 8th of May right?
that means new Date(2012, 5, 31) is the same date as new Date(2012, 6, 1) since June only has 30 days, the Date object wraps the 31st of June round to the 1st of July
Try to use the following code.... This code is worked for me.
var today:Date = new Date(2012,05,08);
var target:Date = new Date(2012,05,01);
if(today > target)
milliseconds = today.getTime() - target.getTime();
milliseconds = target.getTime() - today.getTime();
if(milliseconds > 0)
var seconds:Number = milliseconds / 1000;
var minutes:Number = seconds / 60;
var hours:Number = minutes / 60;
var days:Number = Math.floor(hours / 24);
trace("days left: "+days);
if(days == 0)
trace("not in the future");
Europe, Middle East and Africa