page timing

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
magosla2001
Forum Newbie
Posts: 20
Joined: Sat May 20, 2006 8:54 am

page timing

Post by magosla2001 »

It intended to use php to diplay an image on a web site for three days after it has been uploaded to a webserver.

The was what I did I set an initial date in the format date('dmYHis');

Code: Select all

$initialdate = "02102006141401";
$threedays = "03000000000000"; //for day three
$present_time = date('dmYHis');
if($present_time >= ($initialdate + $threedays)) {
$welcomeImg = "";
}
else {
$welcomeImg = "/images/welcome.gif";  //image displayed within three days
}
This worked only if it falls within the month the site was uploaded but if it happens to be in the next month or the other year it never works as planned.
So I will like someone to help me out on this script of a diffrent method of doing it.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You can use strtotime

Code: Select all

<?php
$start = '2006-09-30';
$limit = strtotime($start . ' +3 day');

echo 'limit: ', date('d.m.Y', $limit);
?>
chocolatetoothpaste
Forum Newbie
Posts: 10
Joined: Wed Sep 06, 2006 10:48 am

Post by chocolatetoothpaste »

I would recommend using the time() function and use unix time stamps, then if you need to add time to it, you can use this formula:

Code: Select all

$initialtime = time();
$threedays = $initialtime + (3 * 24 * 60 * 60);// 3 days x 24 hours x 60 min x 60 sec
What this will do is add 3 days to your time stamp. Just change the 3 to whatever you want.
Post Reply