Well, this is very simple, the only tricky part is making sure that the date is in the right format...
First, add a datetime field to your table:
ALTER TABLE tablename ADD thetime DATETIME NOT NULL;
Next, you'll probably want to set the dates of current entries to now, so you won't get weird results
UPDATE TABLE SET thetime=NOW()
And you'll also want to add an index, so queries will be faster
ALTER TABLE tablename ADD KEY(thetime)
Finally, you'll need to include an input field for the admins to enter the date. Simplest is just using <input type=text>, although it's not very safe - it's easy to input in a wrong format. Nonetheless:
php Code:
Original
- php Code |
|
|
|
<?php
echo "Please enter a date in format YYYY-MM-DD HH:MM:SS: ";
echo "<input name=thedate type=text maxlength=21 value="".date("Y-m-d H:i:s
")."">";
Another option is providing multiple <select> fields, so it's harder to enter an invalid date...
php Code:
Original
- php Code |
|
|
|
<?php
echo "<select name=date_year>";
for ($year=
2003;
$year<=
date("Y");
$year++
) echo "<option value=$year>$year";
// similar for month, day, hour, minute, second (or skip some)
Then, you can combine them into a valid MySQL date format:
php Code:
Original
- php Code |
|
|
|
<?php
$thedate=$_REQUEST["date_year"]."-".$_REQUEST["date_month"]...;
?>
Finally, you need to include it in your INSERT query:
php Code:
Original
- php Code |
|
|
|
<?php
$sql="INSERT INTO tablename(something,thedate) VALUES(somethingelse,$thedate)";
?>
Hope that helped..