在我的会话中,我有当前的会话日期2019-04-01 to 2020-03-31
,我只想打印2019 to 2020
echo $this->session->userdata('start_date');
echo "\t to";
echo $this->session->userdata('end_date');
答案 0 :(得分:2)
使用日期格式
date("Y", strtotime($this->session->userdata('start_date')));
答案 1 :(得分:1)
您可以执行以下操作
Map.of("key", value)
答案 2 :(得分:1)
使用explode
:
<?php
$temp = "2019-04-01 to 2020-03-31";
$test = explode(' to ', $temp);
echo date('Y',strtotime($test[0]))." to ".date('Y',strtotime($test[1]));
?>
答案 3 :(得分:1)
$data = "2019-04-01 to 2020-03-31";
$temp = explode(' to ', $data);
$str1 = explode('-',$temp[0]);
$str2 = explode('-',$temp[1]);
echo str1[0];
echo "\t to";
echo $str1[0];
答案 4 :(得分:0)
$start_date = date("Y", strtotime($this->session->userdata('start_date')));
$end_date= date("Y", strtotime($this->session->userdata('end_date')));
echo $start_date ;
echo "\t to";
echo $end_date;