0

您好我正在尝试使用 DD-MON-YYYY 格式将定义为日期的列转换为日期,但无法正常工作

 select 
   to_date(to_char
   (DESIGN_COMPLETION_DATE,'DD-MON-YYYY'),'DD-MON-YYYY') as Assessment_Completion_Date
    from nbi_dates

也试过

 Select to_date(DESIGN_COMPLETION_DATE,'DD-MON-YYYY') as Assessment_Completion_Date
    from nbi_dates

有效的是,但我无法对其进行任何计算,因为它是 char

 Select to_char(DESIGN_COMPLETION_DATE,'DD-MON-YYYY') as Assessment_Completion_Date
    from nbi_dates

谢谢

4

2 回答 2

1

If you have a DATE that includes a time portion but are only interested in the actual date part, you can use the trunc function:

select trunc(design_completion_date) as assessment_completion_date from nbi_dates

An example of the difference using sysdate; notice the time on the trunc'd version has been set to midnight:

SQL> alter session set nls_date_format = 'DD/MM/YYYY HH24:MI:SS';

Session altered.

SQL> select sysdate, trunc(sysdate) from dual;

SYSDATE             TRUNC(SYSDATE)
------------------- -------------------
11/04/2013 15:14:31 11/04/2013 00:00:00

A DATE has no inherent format. DD-MON-YYYY is a format mask applied to display the date, or to convert it to a string representation, which is usually only necessary for display anyway. What you have as your third option is right for that purpose, but not if you want to do any further date calculations with the result.

于 2013-04-11T14:12:46.503 回答
0
Select to_date(to_char(DESIGN_COMPLETION_DATE,'DD-MON-YYYY'),'DD-MON-YYYY') as Assessment_Completion_Date
from nbi_dates

或者简单地说(如果您想要日期对象进行计算但不用于渲染)

    Select DESIGN_COMPLETION_DATE as Assessment_Completion_Date
from nbi_dates
于 2013-04-11T14:07:37.780 回答