niczak
6/17/2011 - 11:13 PM

DateTime Modification Function

DateTime Modification Function

<?php

fnDate_Modify($sModification)
{
  /*
    $sModification can be any incrementing
    or decrementing string accepted by the
    strtotime() function.
  */

  $sCurrent = date("Y-m-d");
  $oDate = new DateTime($sCurrent);
  $oDate->modify($sModification);
  return $oDate;
}

// Set the date of the $oDate object to next month.
$oDate = fnDate_Modify("next month");

// Reformat the date to Month, Day, Year
echo $oDate->format("F j, Y");

?>