oracle-databaseselecttimestampto-date

how cast varchar to date in oracle


I have a column with NVACHAR2() format but it save date, like this(column name is ORGINALDATE):
1/9/2019 3:46:59 PM
I can not change format of column but I need to date of this. I used from
TO_DATE(ORGINALDATE,'MM/DD/YYYY HH:MI:SS') AS times
And after run show this error : --date format picture ends before converting entire input string


Solution

  • The error seems to be suggesting that the format you have given does not provide information for parsing the entire date with information being left over in the input string. This is then viewed as invalid. The reason this is happening is that the AM/PM of your original data is not captured in the format string. Looking https://www.techonthenet.com/oracle/functions/to_date.php, we see that AM/PM can be added to the format string. Therefore changing your format string to

    MM/DD/YYYY HH:MI:SS PM
    

    should fix it. It should be noted that any of A.M., AM, P.M., or PM appear to be valid and simply specify that time of day information is present.