Page 1 of 1

display text from date to date

Posted: Wed May 25, 2005 8:05 pm
by bogyit
Hi :)
this is my first post here.. seems a nice forum

I go straight to my problem: I'm trying to do a script that lets me display different texts in different days.. this is not very difficult with this kind of code:

Code: Select all

$data = date("d.m.Y");
// files to include
if ($data=="26.05.2005") { include "alfa.html"; }
if ($data=="29.05.2005") { include "beta.html"; }
if ($data=="01.06.2005") { include "gamma.html"; }
if ($data=="05.06.2005") { include "omega.html"; }
The problem is that after the date specified the file is no more included.. how can I resolve this? For example, how can I display the same file (alfa.html) between 26 may and 29 may? Any ideas?

Thanks in advance.

Posted: Wed May 25, 2005 8:11 pm
by Sphen001
Hi,

Try something like:

Code: Select all

<?php
$data = date("d.m.Y");
// files to include
if ( $data >= "26.05.2005" || $data <= "29.5.2005" )
{
  include "alfa.html";
}
// Do this for all the dates
?>
Hope this helps :D

Sphen001

Posted: Wed May 25, 2005 8:35 pm
by harrisonad
I think there will be a problem with "d.m.Y" format when comparing to each other.
What if you use "Ymd" format so as to make it, for example, "20050526" for "2005-50-26" then do what Sphen001 said.

Code: Select all

$data = date("Ymd");
if ( $data >= "20050526" || $data <= "20050529" )

Posted: Wed May 25, 2005 8:39 pm
by Burrito
or use strtotime() and compare the times you could.

Posted: Wed May 25, 2005 8:54 pm
by bogyit
Thanks for the replies :) I'm trying this way, but seems it doesn't work:

Code: Select all

$data = date("Ymd");
if ( $data >= "20050526" || $data <= "20050530" ) { include "alfa.html"; }
elseif ( $data >= "20050530" || $data <= "20050602" ) { include "beta.html"; }
elseif ( $data >= "20050602" || $data <= "20050606" ) { include "gamma.html"; }
else echo "hmm.. something went wrong";
Even if I change the first two dates (for example to april: 20050426 and 20050430) I always display the first file.. while it has to switch to the else condition.

Now I try also strtotime().. maybe I can get it to work (I hope so) :)