Jump to content

How to check if a datetime field is at default value or not


Scooby08

Recommended Posts

Using MySQL.. Is there a way to make this UPDATE query work either by tweaking what's here or possibly another way? And I don't really want to add another column just to say it's been updated or not..

 

UPDATE
table
SET
graded_on = IF(graded_on = '0000-00-00 00:00:00', NOW(), '0000-00-00 00:00:00')

 

It seems I cannot use the 'graded_on' field within the graded_on if().. Not sure of another way to get it done..

 

As is, it updates any graded_on field that does NOT have a value of '0000-00-00 00:00:00'.. Strange that it's doing the opposite of what it should..

 

Thanks!

 

Well I did my best to explain.. It's pretty straight forward..

 

What I was trying to do was update the 'graded_on' field if the value was set to '0000-00-00 00:00:00', which is the default value for that field.

 

Anyways, I did get it working with the following, but I read that it's not too efficient to run an IF statement within the WHERE clause.. Any thoughts?

 

UPDATE
table
SET
graded_on = NOW()
WHERE
event_status = 'Final' AND IF(graded_on = '0000-00-00 00:00:00', 1, 0)

 

Thanks..

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.