inserting/retrieving current date and date of form submissio

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

inserting/retrieving current date and date of form submissio

Post 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
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post 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,
djot
Forum Contributor
Posts: 313
Joined: Wed Jan 14, 2004 10:21 am
Location: planet earth
Contact:

Post 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
-
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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
Post Reply