Jump to content

[SOLVED] PHP current date - 1 day....used for a mysql query????


Recommended Posts

Well I am trying to take the current date - 1 day to check my Database for users who joined at least 1 day ago form the current date....here is my code....

 

$cur_return = date("Y-m-d H:i:s");

$date = explode('-', $cur_return);

$user_date  = date("Y-m-d H:i:s", mktime(0,0,0, $date[1], $date[2]-1, $date[0]));

// So $user_date is the current date - 1 day.....now I need to search the DB for any users who's join date is greater than this. For instance, the date is May 26th well with this would make it  			2007-05-25 00:00:00.

                $RecentUser = 'SELECT username FROM ls_users 
                        WHERE date_joined > '.$user_date;
                $ResultUser = mysql_query($RecentUser);
                $getrow = mysql_fetch_array($ResultUser);
                echo '<li><a href="#"><img src="{skin}files/r1.jpg" alt="Username"><span>'.$getrow['username'].'</span></a></li>';

 

 

now for some odd reason this does not work....I know that the current date - 1 day works, because I did an echo on $user_date and it was " 2007-05-25 00:00:00" which is in the correct format as the date_joined field in the database. Any help would be much appreciated thanks.... :)

I like to use the strtotime() function.

<?php
$one_day_ago = date('Y-m-d',strtotime('-1 day'));
?>

 

Ken

 

That's a good way.  You don't have to remember which parameter in mktime() is the day.  I always have to reference the manual.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.