This blog site is not meant to be any information that is distributed to the general public. It is to serve as shared documentation between the DNSTC developers; however, if you find something useful and would like to use it, go right ahead.

Monday, February 14, 2011

Adding or Subtracting Dates in PHP

Working with dates within PHP sometimes come in handy, yet the syntax is not quite something that is easy to remember. You can add or subtract; days, months and years to the current date by using the mktime() function.


Here is some quick PHP code to add a month to the current date:
$next_month = mktime(0, 0, 0, date("m")+1, date("d"), date("y"));
$outDate = date("Y-m-d", $next_month);

For more on the mktime() function: http://php.net/manual/en/function.mktime.php


For more on the date() format function: http://php.net/manual/en/function.date.php

No comments:

Post a Comment