sqlserver中如何取日期的年月

2024-11-15 15:03:45
推荐回答(1个)
回答1:

这个,你只能把这个读取出来的数据当字符串处理了!!
用空格去分解这个字段,保存在数组里,然后提取第一个为月份,第二个为日期,第三个为年份,第四个为小时和分钟,已经上下午
$time
=
$rs["lastlogin"];
$times
=
explode("
",$time);
$month
=
$times[0];
$day
=
$times[1];
$year
=
$times[2];
$hour
=
substr($times[3],0,2);
$minute
=
substr($times[3],3,2);
if(substr($times[3],5,1)=='p')
{
$hour
=
intval($hour);
if($hour<12)
{
$hour
+=
12;
}
}
$realtime
=
$year."-".$month."-"."day"."
".$hour.":".$minute.":00";
echo
$realtime;