1. mysql convert a timestamp string yyyy-mm-dd hh:mm:ss into yyyy-mm-dd
时间: 2024-03-02 13:29:24 浏览: 173
To convert a timestamp string from the format `yyyy-mm-dd hh:mm:ss` to `yyyy-mm-dd` in MySQL, you can use theDATE()` function. Here's an example:
```sql
SELECT DATE('yyyy-mm-dd hh:mm:ss') AS converted_date;
```
Replace `'yyyy-mm-dd hh:mm:ss'` with your actual timestamp string. The `DATE()` function extracts the date from a datetime or timestamp value.
Note that the resulting `converted_date` will be of the `DATE` type, not a string. If you want to display it as a string in the format `yyyy-mm-dd`, you can use the `DATE_FORMAT()` function:
```sql
SELECT DATE_FORMAT('yyyy-mm-dd hh:mm:ss', '%Y-%m-%d') AS converted_date;
```
Again, replace `'yyyy-mm-dd hh:mm:ss'` with your timestamp string. The `%Y-%m-%d` format specifier represents the year, month, and day respectively.
I hope this helps! Let me know if you have any further questions.
阅读全文