18 January 2026:


This forum is now archived and is in read-only mode. Please continue discussions on our improved new Sahi Pro Community forum.



Sahi Pro is an enterprise grade test automation platform which can automate web, mobile, API, windows and java based applications and SAP.

How to get dates between two dates in an array?

vijaysaimsvijaysaims Members
edited November -1 in Sahi - Open Source
I want to get dates between two dates in an array. The days are in DD/MM/YYYY format
It should be like

function getDatesInRange($start, $end)
{




}
getDatesInRange("01/01/2012", "15/01/2012");

for($i=0; $i<$dateArray.length; $i++)
{
_alert($dateArray[$i]);
}

Comments

  • Hi vijay

    is this helping? http://sahi.co.in/forums/viewtopic.php?id=3340

    maybe you cloud parse your $start and $end to milliseconds, then always increment $start by the number of milliseconds in a day until you reached $end...
    now parse back every step to a readable date and write them into an array?
    Seems no very efficient approach.. but shoudl work without worrying about 30/31/28 days/month etc

    Regards
    Wormi
  • This is working...



    function getDates($startDate,$endDate)
    {
    $dateArray=[$startDate];
    $startDate=$startDate.split("/");
    $endDate=$endDate.split("/");
    $startDate=$startDate[1]+"/"+$startDate[0]+"/"+$startDate[2];
    $endDate=$endDate[1]+"/"+$endDate[0]+"/"+$endDate[2];
    var $d = new Date($startDate);
    var $e=new Date($endDate);
    var $f = $e - $d;
    var $numDays = Math.floor($f / 1000 / 60 / 60 / 24);
    for (var $i = 0; $i <$numDays; $i++)
    {
    $d = new Date($d.setDate($d.getDate() + 1));
    $Day=$d.getDate();
    if($Day<10)
    {
    $Day=$Day.toString();
    $Day="0"+$Day;
    }
    var $Ndate = $Day+ "/"+$d.getMonth()+1+"/"+ $d.getFullYear();
    $dateArray.push($Ndate)
    return($dateArray);
    }
    }
    // getDates("01/01/2012","05/01/2012");
Sign In or Register to comment.