Thinkphp6 处理oracle日期型字段
2022-11-24 11:10:29
177
{{single.collect_count}}

thinkphp 处理oracle日期型字段的时候,只能获取到日期,无法获取具体的时间,在需要使用具体时间的场景下存在问题。可以通过使用oracle的to_char函数来解决。

代码示例如下:

Examine::where('id', 'like',$id)->field('id,name,to_char(wcsj, \'YYYY-MM-DD HH24:MI:SS\') as wcsj)->order('wcsj', 'desc')->select();

其中Examine是定义的模型,经测试,Examine模型中不需要再对字段wcsj做类型转换,做了类型转换也没影响

class Examine extends Model{// 设置当前模型对应的完整数据表名称protected $table = 'tp_exam';// 设置当前模型的数据库连接protected $connection = 'Exam';protected $pk = 'id';protected $dateFormat = 'Y-m-d h:i:s';protected $type = ['WCSJ'=>'datetime'];}

回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}