I suggest reading the DI technical manual for the to_date and to_char functions.
By your message it seems you are passing a datetime into the to_date function where it needs to be string.
Also I suggest searching the forum before posting, I found these!
https://bobj-board.org/t/200579
https://bobj-board.org/t/197564
Darth Services (BOB member since 2007-11-20)