Skip navigation
Currently Being Moderated

date differnce

May 8, 2012 2:33 AM

Tags: #action_script_3

Hi

        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

                   startDate 8,5,2012

                   endDate 1,6,2012

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.

 
Replies
  • Currently Being Moderated
    May 8, 2012 2:33 AM   in reply to Sumit Agrawal FLash

    use date1.getTime() - date2.getTime() to get the difference in milliseconds and then convert to difference in months, days, hours etc

     
    |
    Mark as:
  • Currently Being Moderated
    May 8, 2012 3:04 AM   in reply to Sumit Agrawal FLash

    the number of days between midnight 8th June and midnight 1st July is 23 days. not sure where you are getting 24 or 25 from

     
    |
    Mark as:
  • Currently Being Moderated
    May 8, 2012 3:08 AM   in reply to Sumit Agrawal FLash

    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

     
    |
    Mark as:
  • Currently Being Moderated
    May 8, 2012 3:31 AM   in reply to Sumit Agrawal FLash

    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);
    var milliseconds:Number;
    if(today > target)
    {
    milliseconds = today.getTime() - target.getTime();
    }
    else
    {
    milliseconds = target.getTime() - today.getTime();
    }
    trace(milliseconds);

    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("its today");
    }
    else
    {
      trace("not in the future"); 
    }
    }

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points