Re: If date is greater than

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



<?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@xxxxxxxxxxxxxx>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

[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux