performing datetime related operations in PHP

While for most datetime operations I would normally convert to Unixtime and perform addition subtraction etc. on the Unixtime integer, you may want to look at the Zend framework Zend_Date class.

This has a lot of the functionality you describe. Although Zend is billed as a "framework" it works exceptionally well as a class library to pick and chose elements from. We routinely include it in projects and then just pull in bits as and when we need them.


PEAR::Date looks like it might have some useful functionality.

PEAR::Calendar might also be useful.


strtotime() is useful but it does have some odd behaviors that can pop-up from time to time if you are not just using it to convert a formatted date/time string.

things like "+1 month" or "-3 days" can sometimes not give you what you expect it to output.