Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help printing a couple dates

Status
Not open for further replies.

rye8261

Technical User
Jul 6, 2003
359
US
I am trying to print out todays date and the previous 6 days, but i cant figure out how to print the earlier dates. Can anyone help me with this? I have tried looking on google for this but cant find anything.

Thanks for any help.

---------------------------------------
 
Code:
<?php

$timestamp = time();
$seconds_in_day = 60 * 60 * 24;
$days = array();

for ($i=0; $i<7; $i++)
{
  $days[] = getdate( $timestamp );
  $timestamp -= $seconds_in_day;
}

// Do stuff with $days

?>

--Chessbot

"Violence is the last refuge of the incompetent." -- Asimov, Foundation
 
Check the function strtotime. May not be the most efficient way, but it gets the job done.
Code:
echo date('m/j',strtotime('today')),"\n";
echo date('m/j',strtotime('yesterday')),"\n";
// etc...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top