I have a column, where the date values are stored in nvarchar
data type.
The date format is dd-mm-yy, dd.mm.yy
Currently I am replacing the -
with .
and comparing with get date, as all dates formats used in other tables are in dd.mm.yyyy
format.
Now consider a scenario where the dates may be in other formats like dd/mm/yyyy
or other date formats, is there any way to check whether the date is valid and compare it with getdate()
Also I find few unknown records are also available like 57937234, I need to ignore them.
As of now I am using this query and it is working fine:
select
A.Value, replace( B.Value,'-','.')
from
smpltbl as A
INNER JOIN
smpltbl as B ON A.MSKEY = B.MSKEY
INNER JOIN
smpltbl as tbl_status ON A.MSKEY = tbl_status.MSKEY
where
A.colname = 'XYZ'
AND B.colname = 'ABC'
AND tbl_status.colname = 'Status'
AND tbl_status.Value = 'OK'
AND B.Value <> '00.00.0000'
and B.Value <>'..'
AND replace( B.Value,'-','.') < cast(convert(nvarchar, GETDATE(), 104)
Can someone kindly help me in accepting the dates in different format an comparing with the system date and the result must be displayed in DD.MM.YYYY
format itself