Re: If date is greater than
| From: | German Geek | Date: | Sun, 20 Oct 2013 03:30:51 +0000 |
| Subject: | Re: If date is greater than | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-322329@lists.php.net to get a copy of this message | ||
<?php
// assuming | is meant to be a space like this:
function dates_range($todaynow) {
$date1 = strtotime("2011-11-01");
$date2 = strtotime("2012-12-31");
if (($todaynow >= $date1) and ($todaynow <= $date2)) {
# do something
}
}
// I would write:
function betweenDates($dateInQuestion, $afterDate, $beforeDate) {
$after = strtotime($afterDate);
$before = strtotime($beforeDate);
$now = strtotime($dateInQuestion);
return $after <= $now && $now <= $before;
}
// in your code you can then write
if (betweenDates('now', '2011-11-01', '2012-12-31')) {
# do something
}
On 20 October 2013 15:44, John Taylor-Johnston
<jt.johnston@usherbrooke.ca>wrote:
> |function dates_range($todaynow)
> { |
> |$date1=strtotime("2011-11-01"**);
> $date2=strtotime("2012-12-31")**;
> if (|||($|||||todaynow |>= $date1) and |||||($|||||||todaynow| <=
> $date2)||)
> || {
> || # do something
> |||| }
> }
> |||
>
Tim-Hinnerk Heuer
Twitter: @geekdenz
Blog: http://www.thheuer.com