On Wed, Jan 15, 2003 at 02:07:42AM -0800, Admin-Stress wrote: > Hi, > > I am new to mySQL, so I need some help. > I have a table, which has record structure like this: > > - customer > - name > - register_date > - expired > > Every day, I add some records, new customers. The field 'expired' is just a flag, >either '1' or > '0'. If register_date is 3 months ago then expired = 1. > > The format of register_date is unixtime, or Epoch. > > How can I update the entire database, for setting the expired field ? > > now = current_unixtime(); > threemonths = 3 * 30 * 24 * 60 * 60; > > select * from table_name where register_date + threemonths < now
Hello Admin-Stress, You can use an UPDATE query to modify one or more fields based on where criteria. Something like this query should meet your needs: UPDATE table SET expired = 1 WHERE expired = 0 AND register_date < NOW() - INTERVAL 3 MONTH; For more information, check the MySQL manual (http://mysql.com/doc/en) and review the sections on UPDATE queries and DATE functions. Cheers! -- Zak Greant <[EMAIL PROTECTED]> | MySQL Advocate | http://zak.fooassociates.com Using and Managing MySQL MySQL Training: Stuttgart, May 19-23, 2003 Visit http://mysql.com/training for more information EFF: Protecting Freedoms on the New Frontier (http://eff.org) --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php