help with a date checking thingy

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
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

help with a date checking thingy

Post by R4000 »

Hey guys :P
I'm having a few probs with a script im trying to write.
i need to do something like:

Code: Select all

if(between("01/03","04/04")){ // if date between 1st March and 4th April
  echo "01/03 - 04/04";
} elseif(between("01/12","01/03")){ // if date between 1st december and 1st march (the year after)
  echo "01/12 - 01/03";
}
It should be a simple little function, but despite all my best efforts, it just won't work!
Any of you know howto do thid?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

do what, specifically? Do you have between() created?
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post by R4000 »

Well i need to certain offers on my website between certain dates.

And no i dont have between() thats what isnt working... and i need help with.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what have you tried so far?
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post by R4000 »

Code: Select all

<?php
function between($fromi, $toi){
 $to = $from = array();
 list ($from['day'], $from['month']) = explode("/", $fromi);
 list ($to['day'], $to['month']) = explode("/", $toi);
 $year = date('Y');
 if($to['month'] < $from['month']) $year += 1;
 $from = mktime ( 0, 0, 0, $from['month'], $from['day'], $year );
 $to = mktime ( 0, 0, 0, $to['month'], $to['day'], $year );
 if(time() >= $from && time() <= $to) return true;
 return false;
}
?>
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

how about

Code: Select all

$now = date('d/m');
return ($fromi <= $now and $now <= $toi);
User avatar
R4000
Forum Contributor
Posts: 168
Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom

Post by R4000 »

erm, weird.... it works now... i dunno what i did while retyping it. but thx anyway :P
Post Reply