Marlo Kuisma
Marlo Kuisma

Reputation: 101

Update all rows in MySQL where DATETIME has passed

What I'm trying to achieve is a scheduled release for articles. I need to write a PHP script that changes a (MySQL) field on every row where a DATETIME column value has passed.

For example: I have a column named release that is the type of DATETIME. Say the release on row X is 2017-03-10 21:48:52. The time now is 2017-03-10 22:01:34. That means the time on the field release on row X has passed. That means I wish to update a field on this row.

How can I create a WHERE statement that finds every row with a passed time.

I think this should be very simple but after a while of searching I couldn't find an answer that would work for me.

Upvotes: 0

Views: 265

Answers (1)

Yury Fedorov
Yury Fedorov

Reputation: 14938

Use a simple comparison operator and NOW() function:

// releases is your table name
// release_date is your field
UPDATE releases WHERE release_date < NOW()

It will update all fields that have release_date less than (before) current date and time.

Upvotes: 2

Related Questions