Getting Relative Dates

// "Last Sunday" gets the sunday of the current week
// "This Sunday" gets the sunday of the current week until the actual date is a wednesday
// "Next Sunday" gets the next sunday no matter what day you are on

//last sunday
echo date("Y-m-d", strtotime("last Sunday"));

//two weeks ago sunday
echo date("Y-m-d", strtotime("last Sunday -1 weeks"));

// two weeks ago sunday plus a day. the second example is just to show that you can stack up the added or subtracted dates in case you need to do so
echo date("Y-m-d", strtotime("last Monday -1 weeks"));
echo date("Y-m-d", strtotime("last Sunday -1 weeks +1 days"));



* Calculates the diference in days between two dates.
* @param string $start_date Start date (format yyyy-mm-dd)
* @param string $end_date End date (format yyyy-mm-dd)
* @param boolean $include_end_date Include end date in calculation (1 day is added)
* @return integer Number of days.
* */
function daysBetweenDates($start_date, $end_date, $include_end_date = false) {

// Timestamp for start date
list($s_year, $s_month, $s_day) = explode("-", $start_date);
$start_date_timestamp = mktime(0, 0, 0, $s_month, $s_day, $s_year);

// Timestamp for end date
list($e_year, $e_month, $e_day) = explode("-", $end_date);
$end_date_timestamp = mktime(0, 0, 0, $e_month, $e_day, $e_year);

// Diference between dates
$diff = ($end_date_timestamp - $start_date_timestamp);
$days = floor($diff / (60 * 60 * 24));

if ($include_end_date)

return $days;


The Date

$time = time();
echo date("m/d/y G:i:s e", $time);
echo "<br/>";
echo "Today is ";
echo date("jS of F Y, a\t g:ia i\n e", $time);