我有这个应用程序,Musicalbums的发布者以Varchar
的形式保存到MySQL数据库中(我对此没有影响)所以它显示的日期如(2014-09-11)。我怎样才能让Releasedate只显示(2014)?我是否必须将其转换为DATETIME
我的MySQl查询如下所示:
SELECT products.pro_id,
products.title AS album_title,
products.genre AS album_genre,
products.coverarttoenailurl AS cover_image,
products.ccws_pro_id AS product_upc,
track_title,
track_duration,
album_id,
physicalReleaseDate,
digitalReleaseDate
FROM products
INNER JOIN track_albumn_information
ON products.ccws_pro_upc = track_albumn_information.product_upc
AND track_albumn_information.artist_id ='".$artist_id."'
ORDER BY physicalReleaseDate, digitalReleaseDate DESC
相关字段为physicalReleaseDate
和digitalReleaseDate
请帮助任何人......
答案 0 :(得分:1)
试试这个...使用mysql的Year函数进行ref。 http://dev.mysql.com/doc/refman/5.5/en/date-and-time-functions.html#function_year
SELECT products.pro_id,products.title AS album_title, products.genre AS album_genre, products.coverarttoenailurl AS cover_image, products.ccws_pro_id
AS product_upc, track_title, track_duration, album_id, Year(physicalReleaseDate) , year(digitalReleaseDate) FROM products INNER JOIN track_albumn_information
ON products.ccws_pro_upc = track_albumn_information.product_upc AND track_albumn_information.artist_id ='".$artist_id."' ORDER BY physicalReleaseDate, digitalReleaseDate DESC
答案 1 :(得分:0)
由于它是varchar列,因此您使用LEFT函数
LEFT(physicalReleaseDate,4)
答案 2 :(得分:0)
答案 3 :(得分:0)
YEAR(STR_TO_DATE(datecolumn,'%Y-%m-%d'))
答案 4 :(得分:-1)
SUBSTR(physicalReleaseDate, 1, 4)
SUBSTR(digitalReleaseDate, 1, 4)