Home > Blockchain >  split datetime from array in codeigniter 3
split datetime from array in codeigniter 3

Time:01-19

my problem is to get date from array. but there is a time from it.

i get data from model

$data['result'] = $this->MTransaksi->cekpengembalian($id_transaksi);

and i want to get datetime

$date4 = $data['result']->tanggal_kembali;

after get the datetime i should split it with explode in php function

$splitTimeStamp = explode(" ",$date4);

and just get the date from it

$date = date('Y-m-d',strtotime($splitTimeStamp));

but the result in view looks like this

enter image description here

so this is full code i wrote

$data['result'] = $this->MTransaksi->cekpengembalian($id_transaksi);
$date4 = $data['result']->tanggal_kembali;
$splitTimeStamp = explode(" ",$date4);
$date = date('Y-m-d',strtotime($splitTimeStamp));

just want to split date and time

CodePudding user response:

You need to update the code as the explode() return an array.

Below I have assigned the array parameters to separate variables and you can use them individually.

$data['result'] = $this->MTransaksi->cekpengembalian($id_transaksi);
$date4 = $data['result']->tanggal_kembali;
$splitTimeStamp = explode(" ",$date4);
$dateObject = $splitTimeStamp[0];
$timeObject = $splitTimeStamp[1];
$date = date('Y-m-d',strtotime($dateObject));

NOTE: You didn't mention your $date4 how it looks otherwise could have provided a more concrete answer.

Hope it helps

  • Related