Start Date and Time & End Date and Time in Magento

public function search1Action()
    {
        $searchText1 = $this->getRequest()->getParam('code');

        /* $todayDate = date('Y-m-d H:i:s');
         $tomorrow = mktime(0, 0, 0, date('m'), date('d')+1, date('y'));
         $tomorrowDate = date('Y-m-d H:i:s', $tomorrow); */
       // $magento_date =  date("M d, Y h:m:s A", Mage::getModel('core/date')->timestamp(time()));
       /* $format = 'M d, y h:m:s A';
        $end_date = $item['end_date'];
        $start_date = $item['start_date'];
        $final_end_date = date($format,strtotime($end_date));
        $final_start_date = date($format,strtotime($start_date));  */

        $news1 = Mage::getModel('news/news')->getCollection()->addFieldToFilter('title',array('like'=>'%'.$searchText1.'%'));
        $result=array();
    $data=$news1->getData();
    $store_id=array();
    $store_name=array();
     foreach($news1 as $sdata)
    {
        $magento_date =  date("Y-m-d H:i:s", Mage::getModel('core/date')->timestamp(time()));
        $format = 'Y-m-d H:i:s';
        $end_date = $sdata['end_date'];
        $start_date = $sdata['start_date'];
        $final_end_date = date($format,strtotime($end_date));
        $final_start_date = date($format,strtotime($start_date));
        if(($final_start_date < $magento_date && $magento_date < $final_end_date) || (($final_start_date < $magento_date) && ($start_date!='') && ($end_date=='') )):
        $result[]=array("id" =>$sdata['news_id'], "data" => $sdata['title'], "filename" => $sdata['filename'], "content" => $sdata['content'], "urlidentifier" => $sdata['urlidentifier']);
   endif;
    }
    $this->getResponse()->setBody(Mage::helper('core')->jsonEncode($result));
}
Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: