最近在优化一个项目,发现程序员为了取一个日期,它不需要后面的秒,为了实现这个功能,程序员竟然建立一个函数来实现,感觉这样非常不合理。
我想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是星期日,所以这个月每个星期从星期日开始。
我想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/