R
R
Roman Gor2014-04-17 10:30:14
PHP
Roman Gor, 2014-04-17 10:30:14

MySQL - how to make a selection by year?

Hello!
In the database, each record has its own timestamp attached, at the PHP level I have a value like "2013".
How to write a query to select records corresponding to a given year?
View request:

SELECT FROM_UNIXTIME(`time_stamp`, '%Y') AS year FROM `announcement` WHERE YEAR(`time_stamp`) = '2013'

does not pass.
Thank you!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Anton, 2014-04-17
@RomanGorbatko

Better WHERE `time_stamp` BETWEEN '2013-01-01 00:00:00' AND '2013-12-31 23:59:59' so that the index is used (of course, if there is one)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question