A
A
Archakov Dennis2015-10-18 18:22:40
MySQL
Archakov Dennis, 2015-10-18 18:22:40

Create a query to search by month?

Help me write a query to find values ​​by month.
There is a table with a list of news. The date column stores the time when the record was added in UNIX (TIMESTAMP) .
How to search directly in the query to select those news that were posted for 9 months (in September)?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Latyshev, 2015-10-18
@magalex

SELECT * FROM table WHERE YEAR(FROM_UNIXTIME(`date`))='2015' AND MONTH(FROM_UNIXTIME(`date`))='9';

R
Ruslan Fedoseev, 2015-10-18
@martin74ua

September 1, 2015 0:0:0 - 1441065600
October 1, 2015 0:0:0 - 1443657600
elementary logic suggests: date >= 1441065600 and date <
1443657600 or corresponding functions in your programming language?
www.cy-pr.com/tools/time here is the first one I found

A
Aleksey Ratnikov, 2015-10-18
@mahoho

SELECT * FROM  table where date BETWEEN UNIX_TIMESTAMP('2015-09-01 00:00:00') AND UNIX_TIMESTAMP('2015-09-30 29:59:59')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question