Datetime - subtract days

I have a members database. I want to display a “NEW” icon for members that have been members less than let’s say 30 days

I use a DateTime field in the database for dates when people sign up.

How can I do this?

Something like


$todaysdate = date('Y-m-d G:i:s');

$subtract_date = $todaysdate - 30; 
//I know this is wrong, but just wanted to show what I want

if ($signupdate < $subtract_date){

echo "display NEW icon";

} else {

echo "don't display";

} 

don’t know…I didn’t get it to work. It showed all new eventhough they were older than 30 days.

why is strtotime(‘2010-05-01 15:03:50’); set to a specific time?

Actually I found a new problem with it.

When I display all results of members and the code is the following:

$signupdate = strtotime(“$signupdate”);

$thirtydaysago = strtotime(‘-30 days’);

if ($signupdate > $thirtydaysago) {
$new = “new member”
}
//displays the rows of members
echo $member $new;

It seems like when it finds the first member that is less than 30 days it keeps outputting “new” members after that row…eventhough they are more than 30 days old.

So, I wonder why it would do that? Any suggestions?

It’s already there, here, maybe this will make it clearer. :slight_smile:


<?php
$signupdate = strtotime('2010-05-01 15:03:50');
$thirtydaysago = strtotime('-30 days');

if($signupdate > $thirtydaysago){
  #new member
}
?>

How do I get in the $signupdate and $todaysdate in all this?

ok, problem fixed. I forgot to use double quotes with $signup date.

Now it seems to work. Thanks for the help guys

I don’t really know what stringtotime() does. It seems to be outputting a number

That number is the number of seconds since 1/1/1970, google unix time for more info.

I’m trying to figure out. I’m just lost in the syntax and I don’t really know what stringtotime() does. It seems to be outputting a number

Signup dates are in this format “2010-04-04 08:37:10”.

So I tried the below and it didn’t work either

$signupdate = strtotime(‘$signupdate’);

$thirtydaysago = strtotime(‘-30 days’);

if($signupdate > $thirtydaysago){
$dateicon = “images/apply.png”;
}


<?php
if(strtotime('2010-05-01 15:03:50') > strtotime('-30 days')){
  #new member
}
?>

Because that’s an example to help you see and understand what’s going on. It wasn’t meant to be a copy/paste fix for your code. With a little thought you should be able to figure out what goes there no?

yes, I just remembered that…sorry about that…easy to forget things sometimes. Thanks for all your inputs. Now it works

if ($signupdate > $thirtydaysago) {
echo “new member”;
}
// else don’t echo new member