Checking if the UNIX timestamp stored in MySQL DB is this weeks or this months?
I have a MySQL
DB, and in one of the tables I have stored the time in which the content was submitted its in the form of a UNIX timestamp, the column is called content_time
. Below are two pseudo examples of queries to demonstrate what I'm trying to accomplish, just not sure how to go by doing this (although I understand I will need do some some comparisons between the current and stored timestamps within the WHERE
clause):
SELECT * FROM content
WHERE content_time = THIS WEEKS
开发者_如何转开发(the content was posted at any time/day within the current week)
SELECT * FROM content
WHERE content_time = THIS MONTHS
(the month and year from content_time match with the current)
Appreciate all help.
See MySQL's Date and Time Functions, specifically FROM_UNIXTIME()
, WEEK()
and MONTH()
. Keep in mind that when checking is it the same week or month you probably also want to check is it the same year.
Another option is to generate start and end timestamps for the time range youre intrested in (ie timestamp for the beginning of the week and for the end of the week) and then use WHERE(content_time BETWEEN start AND end)
精彩评论