kevinkhan Posted August 24, 2010 Share Posted August 24, 2010 Im looking for a query to update a published column to 0 if the value is equal to 4 and it is created more than two days ago. The published field is stored as a unix time stamp as an int data type.. Here is the query i have so far UPDATE Classified set `published`= 0 WHERE `published` = 4 AND `created` > 2 days old here is the structure of the table CREATE TABLE IF NOT EXISTS `Classified` ( `id` int(11) NOT NULL auto_increment, `created` int(11) NOT NULL, `modified` int(11) NOT NULL, `published` tinyint(1) NOT NULL default '0', PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1498 ; can anybody help me with this? Quote Link to comment https://forums.phpfreaks.com/topic/211623-i-need-a-simple-sql-query/ Share on other sites More sharing options...
RussellReal Posted August 24, 2010 Share Posted August 24, 2010 Why is create an integer, why not a date? with it as a date you will be able to use date functions.. namely: http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html#function_datediff Quote Link to comment https://forums.phpfreaks.com/topic/211623-i-need-a-simple-sql-query/#findComment-1103233 Share on other sites More sharing options...
kevinkhan Posted August 24, 2010 Author Share Posted August 24, 2010 im not sure. the guy that built the website used the unit time stamp. I would find it difficult to change it too a datetime data type now.. is there anyway i can write a query to do this with Unix time stamp? Quote Link to comment https://forums.phpfreaks.com/topic/211623-i-need-a-simple-sql-query/#findComment-1103237 Share on other sites More sharing options...
mikosiko Posted August 24, 2010 Share Posted August 24, 2010 play with the TIMESTAMP() , TIMESTAMPADD() , TIMESTAMPDIFF(), UNIX_TIMESTAMP() and FROM_UNIXTIME() functions http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_timestamp Quote Link to comment https://forums.phpfreaks.com/topic/211623-i-need-a-simple-sql-query/#findComment-1103272 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.