Forum Moderators: coopster

Message Too Old, No Replies

Check date using PHP

Want to disable a link if date is older than x

         

adam_tech

2:14 pm on Feb 14, 2009 (gmt 0)

10+ Year Member



Hi,

I have a link witch points to an edit page where a user can edit his/her post, Now, I want to check if date of the post is older than x days, disable editing.

How can that be done in PHP? just a hint may help.

Thanks in advance.

rocknbil

4:05 pm on Feb 14, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome aboard adam_tech!

Assuming you have a field post_date in the record, assuming it's the data type datetime,

$expirehours=12;
$expireunit= 'hour';
$select = "select post_date >= date_sub(now(),interval $expirehours $expireunit) from post_table where record_id='$thisRecordId'";
$result = @mysql_query("$select") or error("Could not check for expire time on post");
$row = mysql_fetch_array($result);
mysql_free_result($result);
if (! ($row[0] > 0)) { error("Edit time has expired"); }

error is of course your error output function; if your post_date field is a date type and not datetime, use curdate() instead, but you won't be able to fine tune it by hours, only by days.