oracle SQL how to remove time from date

前端 未结 5 681
小鲜肉
小鲜肉 2020-12-03 02:48

I have a column named StartDate containing a date in this format: 03-03-2012 15:22

What I need is to convert it to date. It should be looki

5条回答
  •  情深已故
    2020-12-03 03:07

    When you convert your string to a date you need to match the date mask to the format in the string. This includes a time element, which you need to remove with truncation:

    select 
        p1.PA_VALUE as StartDate,
        p2.PA_VALUE as EndDate
    from WP_Work p 
    LEFT JOIN PARAMETER p1 on p1.WP_ID=p.WP_ID AND p1.NAME = 'StartDate'
    LEFT JOIN PARAMETER p2 on p2.WP_ID=p.WP_ID AND p2.NAME = 'Date_To'
    WHERE p.TYPE = 'EventManagement2'
    AND trunc(TO_DATE(p1.PA_VALUE, 'DD-MM-YYYY HH24:MI')) >= TO_DATE('25/10/2012', 'DD/MM/YYYY')
    AND trunc(TO_DATE(p2.PA_VALUE, 'DD-MM-YYYY HH24:MI')) <= TO_DATE('26/10/2012', 'DD/MM/YYYY')
    

提交回复
热议问题