Auto Date & Time.. Search & Display

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
stevesoler
Forum Newbie
Posts: 7
Joined: Sun Jun 30, 2002 4:11 am

Auto Date & Time.. Search & Display

Post by stevesoler »

Hello everyone! This is regarding PHP & MySQL.

I'm creating a web form for users to enter their comments and submit the form which will add the comments to a MySQL table. I would then be able to access an admin form that will allow me to retrieve the submitted records of comments.

My Questions:

In the web user's form how can I automatically insert the date & time that they submitted the comment into a column or columns (date & time in one field or separate fields) of the database record?

In the admin form how can I be able to search for submitted comments by specific date and date ranges (using entry fields) or by pre-determined date ranges (last 7 days, last 14 days, last 30 days, last 2 months, etc.. using a pop down menu)? Note: I would not need to search by time, but would like records sorted by date & time.

Finally, when the results are retrieved on both the list as well as the detailed record page, how can I display the date and time that was automatically inserted so that it displays in a readable format (Sat. Jan. 5, 2002, 3:15 PM)?

Many thanks to anyone who can help me with this!
- Steve 8)

Just incase you need to know.. my current setup is:
Solaris 2.7 release 05/99
Apache 1.3.3
MySQL Version 11.15 Distribution 3.23.43
PHP 4.1.0 Apache Module
will
Forum Contributor
Posts: 120
Joined: Fri Jun 21, 2002 9:38 am
Location: Memphis, TN

Post by will »

if you use a mysql column of type "DATETIME", all this can be done pretty easily....

when inserting into the database, set that column equal to now()

example

Code: Select all

mysql_query("INSERT INTO myTable set date=now()");
when you query the things from the DB, add "ORDER BY date" (or whatever your field name is) to the end of the query to sort the results by date

to retrieve dates in a custom format, use the mysql date_format() function...
http://www.mysql.com/doc/D/a/Date_and_t ... tions.html
Post Reply