0

I have a mysql database 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 :-)

Bruce
  • 1

2 Answers2

0

This should get you started...

SELECT DAY(`datestamp`) AS `day`,
       MONTH(`datestamp`) AS `month`,
       YEAR(`datestamp`) AS `year`,
       QUARTER(`datestamp`) AS `quarter`
  FROM `table`;
alex
  • 479,566
  • 201
  • 878
  • 984
  • Thanks - this is what did it... 'UPDATE `fourg124_lime2`.`lime_survey_81823` SET `Year` = YEAR(datestamp); UPDATE `fourg124_lime2`.`lime_survey_81823` SET `Quarter` = QUARTER(datestamp); UPDATE `fourg124_lime2`.`lime_survey_81823` SET `Month` = MONTH(datestamp); UPDATE `fourg124_lime2`.`lime_survey_81823` SET `Date` = DAYOFMONTH(datestamp);' – Bruce Jun 19 '11 at 11:46
0

This should work:

SELECT MONTH(`datestamp`) AS `datemonth`, 
DAY(`datestamp`) AS `dateday`,
YEAR(`datestamp`) AS `dateyear`,
QUARTER(`datestamp`) AS `datequarter`
FROM `table`;
Abhay
  • 6,545
  • 2
  • 22
  • 17
  • Thank you,this is what did it... 'UPDATE `fourg124_lime2`.`lime_survey_81823` SET `Year` = YEAR(datestamp); UPDATE `fourg124_lime2`.`lime_survey_81823` SET `Quarter` = QUARTER(datestamp); UPDATE `fourg124_lime2`.`lime_survey_81823` SET `Month` = MONTH(datestamp); UPDATE `fourg124_lime2`.`lime_survey_81823` SET `Date` = DAYOFMONTH(datestamp);' – Bruce Jun 19 '11 at 11:47