mysql convert a timestamp string yyyy-mm-dd hh:mm:ss into yyyy-mm-dd
时间: 2024-03-02 18:29:23 浏览: 19
To convert a timestamp string in the format 'yyyy-mm-dd hh:mm:ss' into 'yyyy-mm-dd' in MySQL, you can use the DATE() 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 part from the timestamp string and returns it in the format 'yyyy-mm-dd'.
Hope this helps! Let me know if you have any more questions.
相关问题
1. mysql convert a timestamp string yyyy-mm-dd hh:mm:ss into yyyy-mm-dd
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.
mysql时间戳转yyyy-MM-dd HH:mm:ss格式
可以使用MySQL内置的DATE_FORMAT函数将Unix时间戳转换为指定的日期时间格式,具体的SQL语句如下:
```
SELECT DATE_FORMAT(FROM_UNIXTIME(timestamp), '%Y-%m-%d %H:%i:%s') as datetime FROM your_table;
```
其中,`timestamp`为Unix时间戳对应的字段名,`your_table`为表名。执行上述查询语句后,可以得到格式为`yyyy-MM-dd HH:mm:ss`的日期时间。