Forum Moderators: coopster
So when the time entered is 18:15, they should not be allowed to edit it anymore after 17:45. Does anyone know how to check for this?
Help is greatly appreciated.
Thanks in advance,
Stefan
#1 - at the databse level. You need to modify the SQL query like this:
"select * from my_table where DATE_ADD(posting_date, INTERVAL 30 MINUTE) < NOW()"
my_table - the table name.
posting_date - the column where you store the posting date.
If the query return a result, the user may edit his entry. Else - the 30 minutes has passed.
#2 - using PHP. After you retreive the entry information, including the posting date. Lets suppose all the information is retreived as array with name $data.
if($data < date("Y-m-d H:i:s", time() - 1800)){
//the user should be able to edit his entry
}
These may not work immediately, I did not tested, but this is the way.
When I run this (to test the time):
echo date("Y-m-d H:i:s"); I get 2 different times:
My main server: 2008-01-13 14:12:53
My backup server: 2008-01-13 15:12:30
The time from my backup server is the correct one. Is there a way to retreive the correct time when the time of the server is incorrect?
If you have PHP5 installed, use the date_default_timezone_set() [php.net] function.
Else, you may change the time zone via .htaccess file:
php_value date.timezone Europe/London
Start a phpinfo() stript at your backup server and look for the "date.timezone" value.
$dbdatetime = "16:28"; // Stored in DB like this
echo "Database time: ".$dbdatetime."<BR><BR>";
echo "Server time: ".date("H:i")."<BR>";
echo "Server time + hour (GMT + 1): ".date("H:i", time() + 3600)."<BR>";
echo "Server time - 30 min: ".date("H:i", time() + 1800)."<BR>";
if($dbdatetime < date("H:i", time() + 1800)){echo "<BR>Allowed";}
else {echo "<BR>Not allowed";}
Thank you for your help!