I have inserted a field with a format like this 'Jul 08, 2019 (10:57 AM)'.
now i want to compare dates but this is a string datatype not date, i tried to convert it to date before comparing with date, it fails and gives error i tried Convert function and Cast function
CONVERT(date, 'Jul 08, 2019 (10:57 AM)')
Cast('Jul 08, 2019 (10:57 AM)' as date)
is there any way to convert it or to compare it with date like this format 'MM/DD/YYYY'
CONVERTsupports various styles. This particular format isn't one of them, but you can manipulate the string first so it does match one of these formats (e.g.SELECT CONVERT(DATETIME, REPLACE(REPLACE('Jul 08, 2019 (10:57 AM)', '(', ''), ')', ''), 100)). Do try to change these values once and for all so all future queries can simply useDATETIMEfor comparison; do not keep this conversion around in queries.