📅  最后修改于: 2023-12-03 14:47:21.794000             🧑  作者: Mango
This SQL code is used to convert a date string in the format 'DD-MM-YYYY' to a date format that can be used in SQL queries.
SELECT STR_TO_DATE(date_seance1,'DD-MM-YYYY')
Suppose there is a database table called 'seances' that contains a date column called 'date_seance1', with dates stored in the format 'DD-MM-YYYY'. To select the date in a different format, you can use the following SQL code:
SELECT STR_TO_DATE(date_seance1,'DD-MM-YYYY') AS new_date_format
FROM seances;
In this example, the 'STR_TO_DATE' function will convert the date string to the default date format of MySQL, which is 'YYYY-MM-DD'. The 'AS' keyword is used to give the resulting column a new name, 'new_date_format'.
The above code will return a table with a column named 'new_date_format' containing the dates in the new format.
The 'STR_TO_DATE' function is a handy tool for converting date strings into a format that can be used in SQL queries. By using this function, you can select, sort or filter data based on date without worrying about the format of date values.