till today when i was working with MySQL and needed to perform actions with date/time i was using int column with unix timestamp and there was no problems, but today after reading some guides i decided to test timestamp column with “current_timestamp” by default.
So i am interested how to select last month data by column where info is in “2012-09-07 00:23:30” format? And maybe there some tricky queries what will give me data from the start of this month (not last 30 days, but from 09-01 00:00:00 till today) ?
This will give you the last month:
This from the start of the month:
The BETWEEN is nothing special, it’s just a shortcut for
Hmm, I guess the NOW() comparison is not actually needed, since all the records will be before now.
So just do:
Dynamic start of current month:
All this does is extract the day of the month from the current date, then subtract that many days less one from it.