日期类型字段的问题。

ciscomcse 2005-01-22 06:25:29
我的一个字段为日期形,里面是 23-1月-82 , 我想计算现在计算机的时间到这个时间的差值,应该是sysdate - 这个字段的值吧,然后将得到的结果用年-月-日的表示方法来显示,说明经历了这长的时间。该如何做?
...全文
100 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cl_oracle 2005-01-25
  • 打赏
  • 举报
回复
mark
GerryYang 2005-01-23
  • 打赏
  • 举报
回复
楼上的正确.
hailensen 2005-01-22
  • 打赏
  • 举报
回复
如果采用一年365天,一月30天的话可以这样实现
create or replace function getdate(stdate date) return varchar2 is
Result varchar2(16);
temp integer;
tyear integer;
tmonth integer;
tday integer;
begin
select (to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd')-stdate) into temp from dual;
select trunc(temp/365,0) into tyear from dual;
select trunc(mod (temp,365)/30,0) into tmonth from dual;
select trunc(mod (temp,30),0) into tday from dual;
select to_char(tyear)||'-'||to_char(tmonth)||'-'||to_char(tday) into result from dual;
return(result);
end getdate;

17,377

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 基础和管理
社区管理员
  • 基础和管理社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧