Date time functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
lynchpin
Forum Commoner
Posts: 60
Joined: Mon Jul 21, 2008 1:31 pm

Date time functions

Post 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
Mark Baker
Forum Regular
Posts: 710
Joined: Thu Oct 30, 2008 6:24 pm

Re: Date time functions

Post 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 />';
 
lynchpin
Forum Commoner
Posts: 60
Joined: Mon Jul 21, 2008 1:31 pm

Re: Date time functions

Post by lynchpin »

Thanks alot.
Post Reply