Re: Setting date as default value

From: Date: Tue, 20 Jun 2000 06:09:50 +0000
Subject: Re: Setting date as default value
Groups: php.db 
Request: Send a blank email to php-db+get-510@lists.php.net to get a copy of this message
Addressed to: Randy Perry <radknee@earthlink.net> php-db@lists.php.net ** Reply to note from Randy Perry <radknee@earthlink.net> Mon, 19 Jun 2000 20:59:33 -0400 > > Can anyone tell me how to set the current date as a default value > with PHP and MySql. I tried using the MySql function CURDATE() as a > default like so: > > ALTER TABLE customer ALTER enter_date SET DEFAULT CURDATE(); > Make enter_date type TIMESTAMP. See section 7.2.6 Date and Time Types in the MySQL manual for more details. or when you add an entry INSERT INTO customer SET enter_date = NOW(), ... If you use 1 and only 1 TIMESTAMP in your field it will be changed to the current time EVERY TIME THE RECORD IS UPDATED. If you use more than one only the first is updated. I usualy use this feature by having two (or more) TIMESTAMP fields in the record: Modified TIMESTAMP, Created TIMESTAMP, You have to set Created = NOW() when you create the record, I usually set Modified too, but even if you don't the 'first timestamp is set to NOW() when the record is updated' rule will set it. (I have a policy of setting every field in the table when I do an INSERT. Rick Widmer Internet Marketing Specialists www.developersdesk.com

« previous php.db (#510) next »