EllisLab text mark
Advanced Search
     
Date Manipulation Class
Posted: 08 July 2009 07:25 PM   [ Ignore ]
Avatar
Joined: 2007-08-14
64 posts

Just made a small library that helped me a lot. Maybe it can be useful for someone. This library can add or subtract days, months or years and return the result in mysql-ready format or timestamp.

Check it out!

 Signature 

vrusso.com.br - CodeIgniter Study Blog & Game Development
vrusso.com.br - CodeIgniter Folder Icons for Leopard
Follow me @vicenterusso

 
Posted: 09 July 2009 11:13 AM   [ Ignore ]   [ # 1 ]   [ Rating: 0 ]
Avatar
Joined: 2006-08-06
918 posts

thanks for sharing… it’s great to see such a nicely formatted and documented contribution.

but, (not to pop your bubble too hard) you need to look at this thread:

http://ellislab.com/forums/viewthread/120895/

basically, get to know the strtotime() function and you won’t need this lib. it’s much easier to let the PHP guys maintain code than to do it yourself!

cheers.

 Signature 

peeker email (imap/pop) | site_migrate | OOCalendar | PhotoBox2 | word_limiter

 
Posted: 09 July 2009 11:22 AM   [ Ignore ]   [ # 2 ]   [ Rating: 0 ]
Joined: 2006-07-14
4237 posts

in php5.3 you can add or substract dates using the date_add and date_sub methods in procedural or OO style.

$date = new DateTime(); // same as time function
echo $date->add(new DateInterval("P5D"))->format('Y-m-d'); 

with the DateTime object the strtotime date modifying functionality is for the modify method

$date = new DateTime(); // same as time function
echo $date->add('+5 day')->format('Y-m-d');