Date arithmetic
Submitted by valerio on Thu, 08/06/2009 - 07:06
To add or subtract only one date component such as hours, days or month use mktime to create the date and date(<component>) as a building block.
For example the expression below will create a date that is 6AM 20 days from today. It will wrap the month automatically so that if today is June 20 it will return July 10.
mktime(6, 0, 0, date("m"), date("d") + 20, date("y"));
To test use
echo date("Y-m-d G:i:s:", mktime(0, 0, 0, date("m"), date("d") + 20, date("y")));
- Login to post comments