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
R4000
Forum Contributor
Posts: 168 Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom
Post
by R4000 » Wed Apr 12, 2006 8:42 am
Hey guys
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?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 12, 2006 9:04 am
do what, specifically? Do you have between() created?
R4000
Forum Contributor
Posts: 168 Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom
Post
by R4000 » Wed Apr 12, 2006 9:06 am
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.
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 12, 2006 9:15 am
what have you tried so far?
R4000
Forum Contributor
Posts: 168 Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom
Post
by R4000 » Wed Apr 12, 2006 9:35 am
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;
}
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Wed Apr 12, 2006 9:38 am
how about
Code: Select all
$now = date('d/m');
return ($fromi <= $now and $now <= $toi);
R4000
Forum Contributor
Posts: 168 Joined: Wed Mar 08, 2006 12:50 pm
Location: Cambridge, United Kingdom
Post
by R4000 » Wed Apr 12, 2006 9:39 am
erm, weird.... it works now... i dunno what i did while retyping it. but thx anyway