Sunday 17 January 2016

Change format date in mysql to indonesian format

 well quick tutorial about change date mysql to indonesia date using codeignter, well copy paste this script bellow, give it name tgl_indonesia_helper.php put inside helper folder

 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');  
 if ( ! function_exists('tgl_indo'))  
 {  
  function tgl_indo($tgl)  
  {  
  $ubah = gmdate($tgl, time()+60*60*8);  
  $pecah = explode("-",$ubah);  
  $tanggal = $pecah[2];  
  $bulan = bulan($pecah[1]);  
  $tahun = $pecah[0];  
  return $tanggal.'-'.$bulan.'-'.$tahun;  
  }  
 }  
 if ( ! function_exists('bulan'))  
 {  
  function bulan($bln)  
  {  
  switch ($bln)  
  {  
   case 1:  
   return "Januari";  
   break;  
   case 2:  
   return "Februari";  
   break;  
   case 3:  
   return "Maret";  
   break;  
   case 4:  
   return "April";  
   break;  
   case 5:  
   return "Mei";  
   break;  
   case 6:  
   return "Juni";  
   break;  
   case 7:  
   return "Juli";  
   break;  
   case 8:  
   return "Agustus";  
   break;  
   case 9:  
   return "September";  
   break;  
   case 10:  
   return "October";  
   break;  
   case 11:  
   return "November";  
   break;  
   case 12:  
   return "Desember";  
   break;  
  }  
  }  
 }  


then don't forget to load in load helper in autoload.php like this

 $autoload['helper'] = array('tgl_indonesia');  


Then goes to your controller welcome copy and paste this
 <?php  
 defined('BASEPATH') OR exit('No direct script access allowed');  
 class Welcome extends CI_Controller {  
  public function index()  
  {  
   echo tgl_indo ('2016-02-11');   
  //$this->load->view('welcome_message');  
  }  
 }  


 then this the results,


Thanks for reading me !

No comments:

Post a Comment