trunc与日期

最近在优化一个项目,发现程序员为了取一个日期,它不需要后面的秒,为了实现这个功能,程序员竟然建立一个函数来实现,感觉这样非常不合理。

我想trunc(sysdate)可以截取日期的年月日,这样截取到秒应该是支持的,看了以下trunc的文档,总结如下:
设置环境变量
set NLS_DATE_FORMAT=YYYY-MM-DD HH24:MI:SS

select sysdate x from dual     /*+当前时间 */
union all
select trunc(sysdate) from dual  /*+取年月日 */
union all
select trunc(sysdate,'yy') from dual /*+取年 */
union all
select trunc(sysdate,'mm') from dual  /*+取年月 */
union all
select trunc(sysdate,'dd') from dual  /*+取年月日 同trunc(sysdate)*/
union all
select trunc(sysdate,'hh24') from dual /*+取年月日时 */
union all
select trunc(sysdate,'mi') from dual  /*+取年月日时分 */
union all
select trunc(sysdate,'ww') from dual  
union all
select trunc(sysdate,'w') from dual
union all
select trunc(sysdate,'q') from dual  /* 取当前季度 */
union all
select trunc(sysdate,'d') from dual  /* 取当前星期,从星期日开始 */


X                    
---------------------
2011-05-16 10:7:29   
2011-05-16 00:0:00   
2011-01-01 00:0:00   
2011-05-01 00:0:00   
2011-05-16 00:0:00   
2011-05-16 10:0:00   
2011-05-16 10:7:00   
2011-05-14 00:0:00   
2011-05-15 00:0:00   
2011-04-01 00:0:00   
2011-05-15 00:0:00   

11 rows selected.


注:
ww表示Week of year (1-53) where week 1 starts on the first day of the year and continues to the seventh day of the year.      2011/1/1是星期六,所以每个星期从星期六开始。
w表示Week of month (1-5) where week 1 starts on the first day of the month and ends on the seventh.     2011/5/1是星期日,所以这个月每个星期从星期日开始。

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/267265/viewspace-695449/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/267265/viewspace-695449/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值