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 use date function in sahi..

ootoot Members
edited November -1 in Sahi - Open Source
Hi..
I m trying to use date Function in my script.
I used $date in my script.The format with which the date needs to be displayed is : ddyyyyhhmn
where dd -date , yyyy-year , hh-hour , mn-minutes.
How can i modify this $date function such that i can get the required format as above.
Please help.

Comments

  • Hi,

    See if this helps:
    function currentDate($seperator){
        var $now = new Date();
        var $monthday;// = $now.getDate();
        if ($now.getDate() < 10)
            $monthday = "0" + $now.getDate();
        else
            $monthday = $now.getDate();
        var $month = $now.getMonth() + 1;
        if ($month < 10)
            $month = "0" + $month;
    
        var $year = $now.getFullYear();
        var $hours = $now.getHours();
        if ($hours < 10)
            $hours = "0" + $hours;
            
        var $minutes = $now.getMinutes();
        if($minutes < 10)
         $minutes = "0" + $minutes;
    
        var $currentDate = $monthday + $seperator + $year + $seperator + $hours + $seperator + $minutes; 
        return $currentDate;
    }
    //Example usages:
    _alert(currentDate("/"));
    _alert(currentDate("-"));
    _alert(currentDate(""));
    
    Regards,
    Pankaj.
  • ootoot Members
    Thanks Pankaj,
    This works fine for me..
  • Welcome :)
Sign In or Register to comment.