This is my string value 20180421
I want to convert this value into 2018/04/21
here my code
$querya="SELECT STR_TO_DATE('$date','%m/%d/%Y');";
but i does not change my string
Your format is already in ISO format, so you can just use date() for the conversion:
select date(?)
You can also use str_to_date() but you need to use the correct format:
$querya = "SELECT STR_TO_DATE(?, '%Y%m%d')";
Note the use of ?. This is a parameter placeholder and indicates that you should pass the value in as a parameter rather than as a variable.
I should point out that 2018/04/21 is a particular format. Dates are stored in an internal format. To get a particular output format, you need to convert them to strings. Here is one solution:
select date_format(date(?), '%Y/%m/%d')
The date() function is optional, because MySQL will correctly convert this string to a date, so you can also use:
select date_format(?, '%Y/%m/%d')