i have a table that looks like this:
yet when i use NOW() in a php mysql insert query it is staying as all zeros?
any idea why?
If you're using it only at the time of
INSERT, you could make the field a
TIMESTAMP and set a default of
Without knowing more about the code it's difficult to suggest much else.
CREATE TABLE example ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, msg TEXT, msg_sent_datetime TIMESTAMP DEFAULT CURRENT_TIMESTAMP );
Also, if you want it to always update when there's a change to the row, you can add the
ON UPDATE CURRENT_TIMESTAMP property to the table definition:
CREATE TABLE example ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, msg TEXT, msg_sent_datetime TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP );
Of course, all of this is totally dependent on switching to
TIMESTAMP which you may not want