I'm trying to filter out some records by date, but the datetime field seems to be stored as varchar, and I'm struggling to convert it. Below is sample data:
ID DateField 0002 14/04/1989 01:30 0003 16/04/1989 09:45 0004 16/04/1989 06:00 0005 19/04/1989 01:07 0006 21/04/1989 16:03
When i use
cast(Datefield as datetime)
The following error message appears:
Msg 241, Level 16, State 1, Line 1 Conversion failed when converting date and/or time from character string.
Edit - this actually displays the results in a date and time format, but with an error message, why?
What is the best way to convert my date field to a valid date and time format? Thanks
source share