RE: MySQL Ques: default for date field be current date

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> I'm trying to convert an ASP/Access tutorial to PHP/MySQL and have a
> question regarding MySQL.
> 
> In Access one can create a date field and set the default to "Date()"
to
> get
> the current date but according to the mysql manual:
> 
> http://www.mysql.com/doc/en/CREATE_TABLE.html
> 
> > Default values must be constants. This means, for example, that you
> cannot set
> > the default for a date column to be the value of a function such as
> NOW() or
> > CURRENT_DATE.
> 
> Is there any other way to have MySQL automate this? I've heard of
> something
> called stored procedures but am unfamiliar. -- Must this be done on
the
> scripting side?

If you make your column a TIMESTAMP, it will be updated with the current
time when the row is inserted or updated, unless you set it to a
specific time. 

So, if a table has two columns, name and time, then you can do this and
the time column will be set to the current date time. 

INSERT INTO table (name, time) VALUES ('name',NULL);
INSERT INTO table (name) VALUES ('name');

Hope that helps. 

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux