In phpMyAdmin, I have a table that contiains a 'datetime' field. When adding a new record to that table, the 'datetime' field automatically sets according to the currect date and time.
I created an online form to create a new record but found that it does not add the current date and time like phpMyAdmin. I suppose it is a PHP script. Does anyone know what it is? or how this works?
Current Date and Time
Moderator: General Moderators
mysql.com
I'm pretty darn sure that most of the users here know how to use date and time functions or at least how to look them up.
If it is mysql db related try mysql.com
But since you didn't seem to know about this reference try this link
http://www.mysql.com/doc/en/Date_and_ti ... tions.html
and about a third of the way down they talk about now() and UNIX_TIMESTAMP() and the like
phpScott
If it is mysql db related try mysql.com
But since you didn't seem to know about this reference try this link
http://www.mysql.com/doc/en/Date_and_ti ... tions.html
and about a third of the way down they talk about now() and UNIX_TIMESTAMP() and the like
phpScott
I don't know MySQL (I use PostGreSQL), but in PostGreSQL I would do what you want by doing something like
Now I've never stried using now() as a default in pgsql, but I think it works and doesn't get resolved at table creation time, but at row insert time. (SERIAL is like MySQL's AUTO INCREMENT.)
I would then normally insert into foo using
Values for both fooid and date will be automatically generated and inserted to make a complete row.
Code: Select all
CREATE TABLE foo (
fooid SERIAL PRIMARY KEY,
date TIMESTAMP NOT NULL DEFAULT now(),
record TEXT NOT NULL
);I would then normally insert into foo using
Code: Select all
INSERT INTO foo (record) VALUES('Stuff to save');