I need to query the database directly using php. I need to limit my query to nodes created in the current year. I know that the node table contains the date the node was created in the 'created' column and that this contains a date as a timestamp.

I am not sure how to get the current year and express it as a range of timestamps and return only nodes that were created between the two timestamps.

1 Answer 1


You don't need to make any tricks like that to compare a timestamp to the current year.

You can obtain the year of the timestamp by using the PHP date function:

date('Y', 1394010573)

will return


You can obtain the current year by using the same function but without mentionning any timestamp (it will take the current date by default):


Knowing this, you can easily limit your query.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.