You are here: Re: [PHP] if(date("Y-m-d") > « PHP « IT news, forums, messages
Re: [PHP] if(date("Y-m-d") >

Posted by Andrew Kreps on 10/04/86 11:05

On Mon, 10 Jan 2005 13:08:28 -0500, John Taylor-Johnston
<taylorjo@collegesherbrooke.qc.ca> wrote:
> Hi,
> I would like some help to improve this script. I'm a teacher with a schedule of 17 weeks.
> Instead of using if(date("Y-m-d") >= $week3) I would like to do a "for i = 1 to 17" and if the current date date("Y-m-d") = week[i] I would like to echo "This is week $week[i]";
>
> Can someone show me how please?

Ok, let me take another stab at this and answer the actual question
you asked. What can I say, I haven't had my coffee this morning. :)

Try this code:

$weeks = array ("20050107", "20050110", "20050115");

for ($i = count($weeks) - 1; $i >= 0; $i--)
{
if (date ("Ymd") >= $weeks[$i])
{
print "This is week " . ($i + 1);
break;
}
}

It counts backwards, since you'll want to test the latest week first.
You could count forward in the for loop if you create the weeks array
with the weeks counting down. I don't particuarly like having a break
in the loop, but it gets the job done. If you didn't have it in
there, you would see the print statement for every week that has
passed, as opposed to the current one.

Was this a better answer?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация