Oracle date format problem

I have the following strange problem in Oracle

(Please keep in mind that I have little experience in SQL and even less in Oracle).

If I do this:

SELECT TO_CHAR(sysdate, 'YYYY-MM-DD HH24:MI') FROM dual

I get this: 2010-12-02 18:39

All fine there.

However, if I do this:

UPDATE favorite_item
SET favorite_item.last_used_date = TO_DATE(sysdate, 'YYYY-MM-DD HH24:MI')
WHERE favorite_item.favorite_item_id = 1

I get this in my database: 10-DEC-02

Which is the 10th of December '02 which is not correct

If I do this to confirm:

SELECT TO_CHAR(favorite_item.last_used_date, 'YYYY-MM-DD HH24:MI') AS last_used_date
    FROM favorite_item
    WHERE favorite_item.favorite_item_id = 1   

I get this: 0002-12-10 00:00

Which is completely wrong.

What am I doing wrong? I feel that the date setting is not working correctly.

Thanks in advance for your help.

Answers


Don't use TO_DATE() on sysdate; sysdate is already a date.

UPDATE favorite_item  
SET favorite_item.last_used_date = sysdate  
WHERE favorite_item.favorite_item_id = 1`

Need Your Help

Writing Binary To file in Visual Basic with the intent of unreadability

vb.net binary

I am working on a program that creates a "license" file. This file is expected to be binary, containing a name, today's date, a warning date, an expiration date, and a preference of Metric or Impe...

How to synchronously access webbrowser.navigate

c# winforms

How to get the html after navigating from webbrowser like as below in the code. This a dll library that can be used in other projects and it is not a winforms. After calling navigate it does not wa...