0

my function is it is showing like Feb 22,2017 12:00:00 AM i need to display current time.

 public function ws_getPunchHistory($custid,$intime,$outtime,$inlocation,$outlocation,$punchstatus,$create_at)
     {




   if(Mage::getSingleton('customer/session')->isLoggedIn()){
    }
    else{
        $res["error"] = "Invalid request";
        return $res;
    }
    $res = array();
    $data = array();
    $custid = Mage::getSingleton('customer/session')->getId();
    if ($custid != '')
    {   
        $date= date_default_timezone_set('Asia/Kolkata');
        //$current = date('Y-m-d H:i:s');
         $current = date('Y-m-d H:i:s');
        $collection = Mage::getModel("manager/asmtracker")->getCollection()
                                                           ->addFieldToFilter('manager_id','64648')
                                                           ->addFieldToFilter('create_at', array('eq' =>$current))
                                                           ->addFieldToFilter('punch_in_time', array('null' => true))
                                                           ->getFirstItem();

    //print_r($collection);


        try{
            $data = array(
                'manager_id' => strval($custid),
                'punch_in_time' => strval($intime),
                'punch_out_time' => strval($outtime),
                'in_coordinates' => strval($inlocation),
                'out_coordinates' => strval($outlocation),
                'status' => $punchstatus,
                'create_at' => $create_at
                );
            // print_r($data);
            $this->_controller = 'adminhtml_asmtracker';
           $smodel = Mage::getModel("manager/asmtracker")->setData($data)->save();

            $res['code'] = 200;
            $res['asmtracker'] = 'ok';               
        }catch(exception $exception){
            $res['code'] = 400;
            $res['asmtrakcer'] = $exception->getMessage();
        }

    }else{
        $res['code'] = 500;
        //$res['asmtrakcer'] = $exception->getMessage();
    }
    return $res;
 }
0

Replace this code :

$date= date_default_timezone_set('Asia/Kolkata');
//$current = date('Y-m-d H:i:s');
$current = date('Y-m-d H:i:s');

with this :

$current = Mage::getModel('core/date')->gmtDate('Y-m-d H:i:s');
| improve this answer | |
0

Then it will be return

$current = date('Y-m-d H:i:s');
$res['current'] = $current;

If you want formating the date

$current = date('M d,Y H:i:s A');

Output Feb 22,2017 12:27:06 PM

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.