How to Create Helper In Code-igniter (CI)

=================
date_diff_helper.php
=================

<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');
/**
 * CodeIgniter and PHPMailer integration as default CI email function will not set tls value
 *
 * @package CodeIgniter
 * @subpackage        Helpers
 * @category        Helpers
 * @author Nilesh Y, Intelliswift
 */
// ------------------------------------------------------------------------

if (!function_exists('time_diff_check')) {

    function time_diff_check($last_time) {
        if (!empty($last_time)) {
            $curent_time = date('Y-m-d H:i:s');
            $start_date = new DateTime($curent_time);
            $end_date = new DateTime($last_time);
            $interval = $start_date->diff($end_date);
            $days = $interval->days;
            return $days;
        } else {
            return 0;
        }
    }

}


/* End of file zend_framework.php */
/* Location: ./application/helpers/zend_framework_helper.php */


To Call the function use.
$this->load->helper('diff_helper');

time_diff_check($last_time);




No comments:

Post a Comment