mysql日期中的年份,MySQL从日期格式中提取年份

《mysql日期中的年份,MySQL从日期格式中提取年份》

I need a mysql query to extract the year from the following date format from a table in my database.

For eg :

subdateshow

—————-

01/17/2009

01/17/2009

01/17/2009

01/17/2009

01/17/2009

the following query didn’t working

select YEAR ( subdateshow ) from table

The column type is varchar. Is there any way to solve this?

解决方案

Since your subdateshow is a VARCHAR column instead of the proper DATE, TIMESTAMP or DATETIME column you have to convert the string to date before you can use YEAR on it:

SELECT YEAR(STR_TO_DATE(subdateshow, “%m/%d/%Y”)) from table

    原文作者:DetonationCP
    原文地址: https://blog.csdn.net/weixin_34268617/article/details/118809112
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞