PHP date() 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

tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Alright, so I've got a UNIX date from the database. How do I add say 5 days to a date that's already in the Unix format?
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Basically, I've got a date in the Unix format. I want to test to see if that time is 5 days older than today. So, in rough psuedo:

Code: Select all

if ($stored_date is 5 days older than $today_date)
   {
   echo "old date";
   }
else
   {
   echo "new date";
   }
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

"Unix dates" are in seconds. So five days would be:

60 sec per minute * 60 minutes per hour * 24 hours * 5 days

or

Code: Select all

$numdays = 5;
$new_date = $old_date + (60 * 60 * 24 * $n_days)
(#10850)
tristanlee85
Forum Contributor
Posts: 172
Joined: Fri Dec 19, 2003 7:28 am

Post by tristanlee85 »

Heh. Ya learn something new everyday. Thank you. I got it to work just fine.
Post Reply