开发者

How do I separate a mysql datestamp field into year, quarter, month and day

I have a mysql d开发者_运维问答atabase with a datestamp field for entries. I'd really like to separate out the year, quarter, month and day into individual columns. I can make the new columns without a problem but I don't know how to write a query that does this easily. I've been playing around with things like this

SELECT MONTH();
FROM `datestamp`

But haven't had any joy...

Any help gratefully received :-)


This should get you started...

SELECT DAY(`datestamp`) AS `day`,
       MONTH(`datestamp`) AS `month`,
       YEAR(`datestamp`) AS `year`,
       QUARTER(`datestamp`) AS `quarter`
  FROM `table`;


This should work:

SELECT MONTH(`datestamp`) AS `datemonth`, 
DAY(`datestamp`) AS `dateday`,
YEAR(`datestamp`) AS `dateyear`,
QUARTER(`datestamp`) AS `datequarter`
FROM `table`;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜