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`;
精彩评论