0

I have a column that is varchar and the value of the the data is a date (i.e. 31.05.2019)

I'm trying to convert the varchar field to a date field using the following function:

date_format(gedruckt,'%d.%m.%Y')

But when this query is executed:

SELECT gedruckt,(date_format(gedruckt,'%d.%m.%Y')) 
FROM tablename;

I get the following result:

+------------+------------------------------------+
|  gedrukt   | (date_format(gedruckt,'%d.%m.%Y')) |
+------------+------------------------------------+
| 31.05.2019 | NULL                               |
| 03.06.2019 | NULL                               |
+------------+------------------------------------+

I want the result to be:

+------------+------------------------------------+
|  gedrukt   | (date_format(gedruckt,'%d.%m.%Y')) |
+------------+------------------------------------+
| 31.05.2019 |                         31.05.2019 |
| 03.06.2019 |                         03.06.2019 |
+------------+------------------------------------+
  • date_format() formats date type value to string type. You need backward - use str_to_date(). – Akina Jun 6 at 8:17
  • @Akina yes that solved it.. thank you! – F T Jun 6 at 8:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.