Page 1 of 1

help with a date checking thingy

Posted: Wed Apr 12, 2006 8:42 am
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?

Posted: Wed Apr 12, 2006 9:04 am
by feyd
do what, specifically? Do you have between() created?

Posted: Wed Apr 12, 2006 9:06 am
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.

Posted: Wed Apr 12, 2006 9:15 am
by feyd
what have you tried so far?

Posted: Wed Apr 12, 2006 9:35 am
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;
}
?>

Posted: Wed Apr 12, 2006 9:38 am
by feyd
how about

Code: Select all

$now = date('d/m');
return ($fromi <= $now and $now <= $toi);

Posted: Wed Apr 12, 2006 9:39 am
by R4000
erm, weird.... it works now... i dunno what i did while retyping it. but thx anyway :P