Forum Moderators: coopster

Message Too Old, No Replies

help with strtotime

         

BlackRaven

5:37 pm on Apr 21, 2007 (gmt 0)

10+ Year Member



I am trying to compare 2 dates, so that if a post is older that 90 days the user is not allowed to edit it. I am storing the post date in mysql in datetime field (2007-04-21 10:53:07). My question is how to user strtotime function to compare the NOW() date&time with the stored one, so if greater that 90 days return true.

cameraman

6:22 pm on Apr 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There's a couple of ways to do it. Sticking with strototime() all the way, you first use it to convert your post date to a unix timestamp:
$check_date = strtotime($post_date);

then you convert the current date to a unix timestamp:
$d9 = strtotime('-90 days',time()); // The second parameter isn't necessary if you're working with current time, included for illustration

If the post timestamp is less than the '90 days ago' timestamp, the post is too old:
if($check_date < $d9)
echo "Post is too old: $post_date<br>\n";
else
echo "Ok you can edit: $post_date<br>\n";

jatar_k

6:52 pm on Apr 21, 2007 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



you could try this recent thread as well
[webmasterworld.com...]