Suppose we have a variable $ a, where the date is January 22, 2012 (the date may vary). We need to run the script only if a month has passed. How to do this?

    2 answers 2

    here you need to turn both dates into timestamps (starting from January 1, 1970), using the function

    > int mktime ( [int hour [, int minute[, int second [, int month [, int day > [, int year [, int is_dst]]]]]]] ) 

    This function returns the number of seconds since January 1, 1970. I think, then you can do it yourself =) Then you just have to turn both dates into tags and compare what's more ...

      As a beginner, try playing around with this:

       <?php //предварительно сохраненное значение предыдущего запуска $prevStart = date('U', strtotime("-31 days")); //или //$prevStart = mktime(0, 0, 0, 12, 22, 2011);//главное не путать аргументы //собственно оффсет, который необходимо выдержать до следующего запуска $monthAgo = date('U', strtotime("-1 month")); //проверочка, так как время неумолимо растет, предыдущее значение должно быть меньше нашего оффсета в рассчете на сегодняшний день if($prevStart <= $monthAgo) //оказывается скрипт не запускался уже месяц //сохраняем текущее время запуска и пускаем скрипт echo "blabla"; else //можно вообще ничего не делать echo "no blabla";