I want to convert a string from varchar 2 to Date in DD-MM-YYYY format. I am storing the date as a string in the ’01-09-2021′ format. I want to pass a date field in SQL query as a date format to retrieve the data using between.
You can simply use the date_format() to convert from varchar2 to date.
Syntex
SELECT DATE_FORMAT(STR_TO_DATE(fieldName, '%D-%M-%Y'), '%Y%m') as DateFormat from tableName;
OR
select date_format(str_to_date('01/01/2021', '%d-%m-%Y'), '%Y%m');
MySQL CAST() Function: You can also convert a string value to date datatype
select cast(“02-08-2020” as date);
Try this
https://stackoverflow.com/questions/18597051/sql-date-format-convert-dd-mm-yy-to-yyyy-mm-dd