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!

 

Link to comment
Share on other sites

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..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.