Nikolai Engel Nikolai Engel - 1 year ago 96
SQL Question

SQL Convert Date from to dd-mm-yyyy

I want to select data which is set in a specific date range. Unfortunately I get the date in this form:

01.05.2016 and 02.06.2016

In the database, the date are in the form:


How can I convert the date in my sql query?

SELECT `artikel`.*
FROM `artikel`
WHERE (buchungsdatum >= '01.05.2016') AND (buchungsdatum <= '02.06.2016')

Answer Source

If this is MySQL, you can use STR_TO_DATE:

SELECT `artikel`.* 
FROM `artikel` 
    buchungsdatum >= STR_TO_DATE('01.05.2016','%d.%m.%Y')
    AND buchungsdatum <= STR_TO_DATE('02.06.2016', '%d.%m.%Y')

Check here for the available date formats.