I have a varchar column which contains date in following format
dd/mm/yyyy
I need to convert the column’s datatype to DATE. I’m using the following query
alter table [tblDocumentRevision]
alter column [RevisionDate] date null
but I get an error
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.
The statement has been terminated.
I’m sure that all the values are in dd/mm/yyyy format. So why is it giving me the error?
Then I added a new column and tried
UPDATE [tblDocumentRevision]
SET NewDate = convert(date,[RevisionDate],103)
WHERE ISDATE([RevisionDate]) = 1
The check for ISDATE() = 1 should filter out those entries that cannot be converted to a DATE.
Then NewDate column has only the values where month and date are both less than or equal to 12 others are null. So I’m clearly seeing a issue with the dd/mm/yyyy format
Can someone please help me to solve this issue?
I used Google to find this. Try setting the format being running
ALTER COLUMN.EDIT
Yields:
Whereas:
Yields: