MySQL DATETIME Question

Associate
Joined
3 Oct 2006
Posts
2,304
Location
London
Hi there,

Is there anyway to get a MySQL database to automatically insert the DATE and TIME, that the entry is created, into the entry you are creating? A bit like an auto incrementing number but for Date and Time I suppose!

Thanks

Jon
 
The field type IS date time, but it doesn't auto enter the date, it just leaves '0000-00-00 00:00:00'. This is the same whether it is set to NULL or NOT NULL (In the NULL Property)
 
Last edited:
Yeah, pretty much. A colleague at work said there was some kind of MySQL function now(). I've no idea how to use it though!
 
NOW() returns a constant time that indicates the time at which the statement began to execute. (Within a stored routine or trigger, NOW() returns the time at which the routine or triggering statement began to execute.)

As of MySQL 5.0.13, SYSDATE() returns the time at which it executes. This differs from the behavior for NOW(), which returns a constant time that indicates the time at which the statement began to execute.
 
Code:
Error

SQL query:

ALTER TABLE `comments` CHANGE `comment_date` `comment_date` DATETIME NOT NULL DEFAULT 'SYSDATE()'

MySQL said: Documentation
#1067 - Invalid default value for 'comment_date'
 
Back
Top Bottom