Page 1 of 1

inserting/retrieving current date and date of form submissio

Posted: Tue Nov 30, 2004 5:56 am
by TheOracle
Hi All,

I want to be able to add the current date and time into a mysql table at the time a form is submitted.

I will then need to be able to retrieve this information and display it in the admin panel I am designing.

Can someone show me how I can achieve this, including the format I wuld need for the mysql column.

Thanks

Posted: Tue Nov 30, 2004 6:11 am
by phpScott
mysql supports a field type called timestamp which will set the date and time of when the record was last updated.

to retrieve the date/time you will need to use date_format() in your select statement.

Code: Select all

SELECT id, date_format(yourDateField,  '%d %m %Y %h $i $s) FROM yourTableName;
should return 30 11 2004 12 11 31
or day, month, year, hour, minute, second

http://dev.mysql.com/doc/mysql/en/Date_ ... tions.html
and look for date_format

Posted: Tue Nov 30, 2004 6:52 am
by TheOracle
Hi phpScott,

Thanks again,

should the characters in your SQL be % or $ or is it correct how you have done it. Also, should the second value in the function be surrounded in single quotes, as you have one at the beggining but not at the end?

Cheers,

Posted: Tue Nov 30, 2004 6:54 am
by djot
-
I always need the timestamp provided by php in my scripts, that's why I never use mysql-timestamps. You can get the actual time(-stamp) with $timestamp = time();
(http://www.php.net/manual/en/function.time.php)

and insert that with your according data of the submitted form.

djot
-

Posted: Tue Nov 30, 2004 8:55 am
by timvw
and offcourse, mysql has it's own set of nice date-and-time functions.
http://dev.mysql.com/doc/mysql/en/Date_ ... tions.html

my favorites: now, dateformat, from_unixtime, unix_timestamp