PHP MySQL Get Time stamped records from Current Year

How do I get records for the current year ? The following does not work.  I have a UNIX Time stamped field in my table.  I need all records in the current year.
<?php
 $get_id = $wpdb->get_results('SELECT term_id AS id, name AS name FROM wp_connections_terms WHERE term_id != 1');
        foreach ($get_id as $row) {
            $name = $row->name;
            $id = $row->id;

            $taxid = $wpdb->get_results("
          SELECT meta_value AS value 
          FROM wp_connections
          WHERE date_added > UNIX_TIMESTAMP(NOW(), INTERVAL 1 YEAR) );

Open in new window

LVL 8
rgranlundAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Is date_added the UNIX_TIMESTAMP field?

If it is you can get the year from it like this,

FROM_UNIXTIME(date_added, "%Y")

and you could get the current year like this,

YEAR(NOW())

So try this.

 SELECT meta_value AS value
 FROM wp_connections
 WHERE FROM_UNIXTIME(date_added, "%Y") = YEAR(NOW())
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rgranlundAuthor Commented:
That was simple enough! Thanks.
0
_agx_Commented:
Just a suggestion. If the date_added column is indexed, best to avoid using functions on it the WHERE clause because it prevents the db from using the index. Instead, it's better to use something like this:

 WHERE date_added >= UNIX_TIMESTAMP(MAKEDATE(Year(curDate()), 1))
 AND      date_added < UNIX_TIMESTAMP(MAKEDATE(Year(curDate())+1, 1))

... which in other words means

 WHERE date_added >= '2018-01-01'
 AND      date_added < '2019-01-01'
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.