开发者

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

开发者 https://www.devze.com 2023-03-14 01:42 出处:网络
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

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

精彩评论

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