Page 1 of 1

Date time functions

Posted: Fri Nov 28, 2008 4:50 am
by lynchpin
Hello Guys,

I am working on a project that involves loads of date /time manipulation. And I need to be able to add/sub days/months/years from a date object or string. But I cant find a suitable function that works. i have seen some scripts using the "add_delta_ymd()" function or "date_add()" function, but they both dont seem to work on my apache server(localhost). I was wondering if there's another way or maybe I am doing something wrong.

I am using apache 2.2.8 and php 5.2.6.

sample code
--------------------------------------------------------------
$t = date("Y-m-d");
$next_day = date_add($t, 0, 0, 1);

echo "next_day";
--------------------------------------------------------------

Thanks

Re: Date time functions

Posted: Fri Nov 28, 2008 4:56 am
by Mark Baker

Code: Select all

 
$date = strtotime('1-Mar-2008');
$yesterday = strtotime('-1 day',$date);
$tomorrow = strtotime('+1 day',$date);
echo 'Yesterday was '.date('d-M-Y',$yesterday).'<br />';
echo 'Tomorrow will be '.date('d-M-Y',$tomorrow).'<br />';
 

Re: Date time functions

Posted: Fri Nov 28, 2008 6:19 am
by lynchpin
Thanks alot.