Seb Spiers Posted August 20, 2006 Share Posted August 20, 2006 Hi There,Ive got a simple html form with a text field in which a date is entered in a dd/mm/yyyy format.I want to be able to manipulte the date by adding and subtracting days.The problem i've found is that if I enter 22/06/1983 and for example do; [code]<? echo ( $date_commencing + 6 ) ; ?>[/code]The output is not 28/06/1983, it simply outputs "28". It uses the numbers before the first "/". I want to handle the date as a date.Can anyone help? :)Ta! :X Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted August 20, 2006 Share Posted August 20, 2006 Use the strtotime (http://www.php.net/strtotime), maketime (http://www.php.net/maketime), and date http://www.php.net/date) functions to accomplish what you want.Essentially, use strtotime to change your string to a unix timestamp, then use maketime or date to add 6 days. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted August 20, 2006 Share Posted August 20, 2006 [code]<?phpfunction add_days($current_time,$days,$format='d/m/Y'){ return date($format,strtotime($current_time)+86400*$days);}echo add_days('22/06/1983','6');?>[/code] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.