For Programmers: Free Programming Magazines  


Home > Archive > PHP SQL > October 2005 > setting default date column to NOW()









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author setting default date column to NOW()
laredotornado@zipmail.com

2005-10-20, 9:56 pm

Hello,
I am running MySQL 4. I was curious, how do you make the DATE or
TIMESTAMP column's default value whatever the time was that the row was
created. I would prefer not to specify the "NOW()" function in my
INSERT statement, but rather would like to have that automatically
happen upon new row creation.

Is it possible?

Thanks, - Dave

IchBin

2005-10-21, 3:56 am

laredotornado@zipmail.com wrote:
> Hello,
> I am running MySQL 4. I was curious, how do you make the DATE or
> TIMESTAMP column's default value whatever the time was that the row was
> created. I would prefer not to specify the "NOW()" function in my
> INSERT statement, but rather would like to have that automatically
> happen upon new row creation.
>
> Is it possible?
>
> Thanks, - Dave
>


If the NULL attribute is not specified, setting the column to NULL sets
it to the current timestamp. Note that a TIMESTAMP column which allows
NULL values will not take on the current timestamp unless either its
default value is defined as CURRENT_TIMESTAMP, or either NOW() or
CURRENT_TIMESTAMP is inserted into the column. In other words, a
TIMESTAMP column defined as NULL will auto-update only if it is created
using a definition such as the following:

CREATE TABLE t (ts NULL DEFAULT CURRENT_TIMESTAMP);


Look at this link
http://dev.mysql.com/doc/refman/5.0...estamp-4-1.html
--


Thanks in Advance...
IchBin, Pocono Lake, Pa, USA
http://weconsultants.servebeer.com/JHackerAppManager
________________________________________
__________________________________

'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com