dongmeiba6151
2016-03-10 17:03
浏览 42
已采纳

在活动记录Codeigniter中将日期格式显示为DD MM YYYY

How would I alter my active record to display my date as DD MM YYYY rather than YYYY MM DD?

Current Display

2016-01-07

Aim Display

07-01-2016

Current View

<?php echo $row->start_date; ?>

Tried View

<?php echo $row->DATE_FORMAT(start_date, '%d/%m/%Y'); ?>

Model

class Profiles_model extends CI_Model

    {

        function get_bank()
        {
            $this->db->where('mem_id', $this->session->userdata("id"));
            $query = $this->db->get('bank');
            return $query->result();
        }

    }
  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • dongyao5843 2016-03-10 17:14
    已采纳

    You can use strtotime() and date() of php as :

    $originalDate = $row->start_date;
    $newDate = date("d-m-Y", strtotime($originalDate));
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报
  • doutan3192 2017-05-31 12:26

    I always prefer to make a helper function in Codeigniter for date formatting because date is very common to use on many pages.

    Codeigniter 3 helper function:

    if(!function_exists('dateFormat'))
    {
        function dateFormat($format='d-m-Y', $givenDate=null)
        {
            return date($format, strtotime($givenDate));
        }
    }
    

    Autoload this helper in your Codeigniter autoload.php and then use it freely anywhere in controller/model/view.

    use in view like:

    <?= dateFormat('d-m-Y',$info->createdDtm) ?>
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题