display text from date to date

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
User avatar
bogyit
Forum Newbie
Posts: 2
Joined: Wed May 25, 2005 7:43 pm
Location: Italy

display text from date to date

Post 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.
Sphen001
Forum Contributor
Posts: 107
Joined: Thu Mar 10, 2005 12:24 pm
Location: Land of the Beaver

Post 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
User avatar
harrisonad
Forum Contributor
Posts: 288
Joined: Fri Oct 15, 2004 4:58 am
Location: Philippines
Contact:

Post 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" )
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

or use strtotime() and compare the times you could.
User avatar
bogyit
Forum Newbie
Posts: 2
Joined: Wed May 25, 2005 7:43 pm
Location: Italy

Post 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) :)
Post Reply