-1
SELECT STR_TO_DATE(SUBSTRING_INDEX(`REPORTDATETIME`,' ',1),'%m/%d/%y') 
FROM crimes 
where REPORTDATETIME like '%1/12/2001%'

it is the query which iam using reportdatetime(varchar) is the column name of table

reportdatetime
1/12/2001 1:30
12/23/2003 1:09
11/12/2001 1:30
5/23/2003 1:09

the result which query gives

2020-1-12

but the result iam expecting is 2001-1-12

usama mirza
  • 1
  • 1
  • 1

1 Answers1

1

Your STR_TO_DATE format should be '%m/%d/%Y' for a four-digit year.

Other peripheral issues to note... I would expect your WHERE clause to catch two different rows (always best to avoid using a leading '%' in LIKE whenever you can). Also, a time of 1:90 looks very strange.

phatfingers
  • 9,770
  • 3
  • 30
  • 44