Skip to content

Instantly share code, notes, and snippets.

@thomaspuppe
Last active December 11, 2015 11:28
Show Gist options
  • Save thomaspuppe/4593700 to your computer and use it in GitHub Desktop.
Save thomaspuppe/4593700 to your computer and use it in GitHub Desktop.
Extract Month and Year from a datetime/timestamp coloumn
### With timestamp/integer coloumn (1354711936)
SELECT
FROM_UNIXTIME(crdate, '%Y') AS year,
FROM_UNIXTIME(crdate, '%M') AS month,
COUNT(uid) AS number
FROM `tx_campeforms_domain_model_contact`
WHERE interest LIKE "%Techniker%"
AND email NOT LIKE "%test.de%"
AND email NOT LIKE "%ondigo.de%"
GROUP BY year, month
ORDER BY year, month
### with datetime coloumn (2012-12-05 13:52:16)
SELECT
extract(month from tweet.creation) AS month,
extract(year from tweet.creation) AS year,
count(tweet.id) AS count
FROM tweet tweet
WHERE tweet.screenname = ?
AND tweet.creation >= ?
GROUP BY year, month
ORDER BY year, month
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment