oracle sql:如何将字符串日期时间转换为指定格式
我已经搜索了一段时间,但似乎找不到这个小问题的答案。
如何将字符串 06-JUL-89 转换为日期时间 06/07/1989? 我尝试过使用如下代码:
TO_CHAR(TO_DATE(BORN,'DD-MON-YY'),'DD/MM/YYYY')
但是,结果显示错误:是 06/07/2089?我该如何解决这个问题?
I've been searching around for a while now, but I can't seem to find the answer to this small problem.
how to convert string 06-JUL-89 to datetime 06/07/1989?
I've tried with code like the following:
TO_CHAR(TO_DATE(BORN,'DD-MON-YY'),'DD/MM/YYYY')
however, the result shows wrong: to be 06/07/2089? how do i solve the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
采用
RR
格式模型。顺便说一句,看起来好像您将日期值存储为字符串。如果是这样,请不要这样做 - 切换到
DATE
数据类型(尽快)。With
RR
format model.By the way, it looks as if you store date values as strings. If so, don't do that - switch to
DATE
datatype (as soon as possible).看来您遇到了 2k 年的问题:
TO_DATE('06-jul-89', 'dd-mon-yy')
=>; 2089年6月7日您必须使用
TO_DATE('06-jul-89', 'dd-mon-rr')
=>; 1989年6月7日It seem that you have the problem of year 2k :
TO_DATE('06-jul-89', 'dd-mon-yy')
=> 06/07/2089You must use
TO_DATE('06-jul-89', 'dd-mon-rr')
=> 06/07/1989