Reply to Re: [PHP] if(date("Y-m-d") >

Your name:

Reply:


Posted by Richard Lynch on 10/04/01 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?

You could also consider using http://php.net/date with the 'W' (ISO-8601
week number of year, weeks starting on Monday (added in PHP 4.1.0))
argument or 'z' (The day of the year (starting from 0)) and divide by 7.

You'd need to compute your offset to your 'first' week that you care
about, but...

<?php
//PHP 4.1.0 and up:
$start_week = date('W', mktime(0, 0, 0, 9, 4, 2005));
echo "This is week: ", date('W', mktime(0, 0, 0, 10, 1, 2005)) -
$start_week, "<BR>\n";
?>

Depending on what you are doing and how you are already storing dates,
this could be cleaner.

Watch out, though, as you'll have issues on New Year's Eve if that's in
the middle of a 17-week period, as I suspect it is...

You could also just use:
<?php
$start_week = mktime(0, 0, 0, 8, 2, 2005);
function seconds_to_week($seconds){
return $seconds / (60*60*24*7);
}
echo "This is week: ", seconds_to_week(mktime(0, 0, 0, 9, 17, 2005)),
"<BR>\n";
?>

--
Like Music?
http://l-i-e.com/artists.htm

[Back to original 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

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