📜  select STR_TO_DATE(date_seance1,'DD-MM-YYYY') - SQL (1)

📅  最后修改于: 2023-12-03 14:47:21.794000             🧑  作者: Mango

Select STR_TO_DATE(date_seance1,'DD-MM-YYYY') - SQL

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.

Syntax
SELECT STR_TO_DATE(date_seance1,'DD-MM-YYYY') 
  • SELECT: This is a standard SQL keyword used to select data from a database.
  • STR_TO_DATE: This is an SQL function that converts a string to a date format.
  • date_seance1: This is the date value that needs to be converted.
  • 'DD-MM-YYYY': This is the format of the date string that needs to be converted.
Example

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.

Conclusion

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.