Catch only the year of a column in MySQL

1

I have a query that has a condition, which checks whether the record is greater than or equal to today's date.

It looks like this:

WHERE t1.bidpack_buy_date => NOW()

Well, it will check if the value of the bidpack_buy_date column is greater than or equal to the current date and time.

In column bidpack_buy_date it gets recorded this way:

2018-01-10 09:00:00

I need that in this condition, it only checks the day, month and year. That is, it will be valid only if it is equal to today's date or after, the time should be considered.

How can I do this?

    
asked by anonymous 10.04.2018 / 19:17

2 answers

2

If you want to check individual, you can use

WHERE YEAR(bidpack_buy_date) => YEAR(NOW())

or

WHERE MONTH(bidpack_buy_date) => MONTH(NOW())

To check the date without the time, then:

WHERE DATE(bidpack_buy_date) => DATE(NOW())

Similarly, to check only the time:

WHERE TIME(bidpack_buy_date) => TIME(NOW())

    
10.04.2018 / 19:19
1

I believe the question has already been answered, but another way is to use the DATE_FORMAT() function:

SELECT * FROM tabela WHERE DATE_FORMAT($data, "%Y%m%d") > DATE_FORMAT(NOW(), "%Y%m%d");

Note: In the link you have the options for formatting the string

If you have a performance difference I can not say, but it should not be exorbitant

    
10.04.2018 / 20:30