Page 1 of 1

page timing

Posted: Mon Oct 02, 2006 10:02 am
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.

Posted: Mon Oct 02, 2006 10:11 am
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);
?>

Posted: Mon Oct 02, 2006 4:43 pm
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.