Date specific conditional

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
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Date specific conditional

Post by seodevhead »

Hey guys... Date and time related stuff is probably my biggest weakness with PHP, but I have a fairly simple problem maybe one of you can help me with.

I am making a part of a webpage that is a conditional that will do something if the current date is October of 2007 or later. So basically, I want to write some code for the page right now, so that when it does turn October, the page displays something different.

Any idea on the best way to do this? Any guidance would be greatly appreciated. Thanks.
User avatar
mikeeeeeeey
Forum Contributor
Posts: 130
Joined: Mon Jul 03, 2006 4:17 am
Location: Huddersfield, UK

Post by mikeeeeeeey »

basically it's just an if statement, with the condition being the date...

Code: Select all

if(date("F") == "October"){
  //execute code for october
}else{
  //execute code for not being october
}
hope it helps
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post by seodevhead »

Hey Mikeeeey... thanks for the help... but the problem I am having difficulty understanding is making the if statement like this, (in pseudo-speak below):

if (date is october 2007 or later)
{ do this }
User avatar
guitarlvr
Forum Contributor
Posts: 245
Joined: Wed Mar 21, 2007 10:35 pm

Post by guitarlvr »

Not the best at dates either but would something like this work:

Code: Select all

if((date("F") >= "October") && (date("Y") >= "2007")){
  //execute code for october 07 or >
}else{
  //execute code for not being october
}
Wayne
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

Code: Select all

if (time() > strtotime('October 2007'))
{

}
User avatar
seodevhead
Forum Regular
Posts: 705
Joined: Sat Oct 08, 2005 8:18 pm
Location: Windermere, FL

Post by seodevhead »

Wow... JCart nailed it perfectly. That's genious. Thanks a bunch guys! :)
Post Reply