Faqts : Business : Programming : Shopping For You : PHP : Function Libraries : Date and Time

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

69 of 74 people (93%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How can I get the date 7 days prior to today?

May 18th, 2000 20:12
Nathan Wallace, Chris Boget, Michael Waples


First method:

  $oneDay  = 86400; // number of seconds in a day
  $today   = date( "U" );
  $weekAgo = $today - ( $oneDay * 7 );
  echo "One week ago was: " . date( "F d, Y", $weekAgo ) . "<br>\n";

Second method:

  $week = strtotime("-1 week");
  or
  $week = strtotime("-7 days");
  echo date("l jS F", $week);