Wednesday, July 28, 2010

How to get past date from today

Here is the code,

$today = strtotime(date('y-m-d'));
for($i=0; $i < 7;$i++)
{
$days[] = date('y-m-d:l',($today-($i*24*60*60)));
}
print_r($days);die;

Output:
Array ( 
    [0] => 10-07-28:Wednesday    
    [1] => 10-07-27:Tuesday 
    [2] => 10-07-26:Monday  
    [3] => 10-07-25:Sunday  
    [4] => 10-07-24:Saturday   
   [5] => 10-07-23:Friday   
   [6] => 10-07-22:Thursday
 ) 


Note: The result might be different as your testing date will be different.

No comments:

Post a Comment