Page 1 of 1
Current Date and Time
Posted: Wed Jun 04, 2003 9:16 am
by AliasBDI
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?
Nobody???
Posted: Wed Jun 04, 2003 12:57 pm
by AliasBDI
Surely somebody knows how that works.
mysql.com
Posted: Wed Jun 04, 2003 1:15 pm
by phpScott
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
Posted: Wed Jun 04, 2003 1:16 pm
by nielsene
I don't know MySQL (I use PostGreSQL), but in PostGreSQL I would do what you want by doing something like
Code: Select all
CREATE TABLE foo (
fooid SERIAL PRIMARY KEY,
date TIMESTAMP NOT NULL DEFAULT now(),
record TEXT NOT NULL
);
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
Code: Select all
INSERT INTO foo (record) VALUES('Stuff to save');
Values for both fooid and date will be automatically generated and inserted to make a complete row.