I have a field of type varchar where I store dates with the d/m/y
example format "5/6/2022"
and I want to convert it to type date
, in the same database, passing to another field of type date
. I tried:
SELECT STR_TO_DATE(fcfacfemi, '%d-%m-%y') FROM FCFAC where id =1
I always get an error.
What is the correct way to do it? Also try:
update fcfac set femi =convert(fcfacfemi,'Y/m/d')
femi
is my type field date
fcfacfemi
is my varchar type field where is the date in string format.
The problem is that you are using
-
and as you say dates contain/
.On the other hand, if your date comes like this:
5/6/2022
I interpret that:0 ... 31
0 ... 12
According to the Reference Manual , you must then use the letters
e
for the day,c
for the month andY
for the year, otherwise you risk updating the dates erroneously.This is how it should work:
Try using date_format, it would be something like this:
https://www.w3schools.com/sql/func_mysql_date_format.asp
thank you all for your time..
in the end it was like this..