Scooby08 Posted February 24, 2011 Share Posted February 24, 2011 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 https://forums.phpfreaks.com/topic/228671-how-to-check-if-a-datetime-field-is-at-default-value-or-not/ Share on other sites More sharing options...
fenway Posted February 24, 2011 Share Posted February 24, 2011 Huh? Link to comment https://forums.phpfreaks.com/topic/228671-how-to-check-if-a-datetime-field-is-at-default-value-or-not/#findComment-1179104 Share on other sites More sharing options...
Scooby08 Posted February 24, 2011 Author Share Posted February 24, 2011 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 https://forums.phpfreaks.com/topic/228671-how-to-check-if-a-datetime-field-is-at-default-value-or-not/#findComment-1179150 Share on other sites More sharing options...
Jessica Posted February 24, 2011 Share Posted February 24, 2011 Why not this? UPDATE table SET graded_on = NOW() WHERE event_status = 'Final' AND graded_on = '0000-00-00 00:00:00' Link to comment https://forums.phpfreaks.com/topic/228671-how-to-check-if-a-datetime-field-is-at-default-value-or-not/#findComment-1179170 Share on other sites More sharing options...
Scooby08 Posted February 24, 2011 Author Share Posted February 24, 2011 Wow did I really over think that one! Yeah that works perfectly obviously.. Thank you for taking my head out of the clouds jesirose!! Link to comment https://forums.phpfreaks.com/topic/228671-how-to-check-if-a-datetime-field-is-at-default-value-or-not/#findComment-1179175 Share on other sites More sharing options...
Jessica Posted February 24, 2011 Share Posted February 24, 2011 Wow did I really over think that one! Yeah, ya did. :-P It happens. Link to comment https://forums.phpfreaks.com/topic/228671-how-to-check-if-a-datetime-field-is-at-default-value-or-not/#findComment-1179176 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.