{"id":2926,"date":"2014-03-10T12:58:06","date_gmt":"2014-03-10T12:58:06","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/10\/how-do-i-get-the-datetimestamp-since-last-cron-run-collection-of-common-programming-errors\/"},"modified":"2014-03-10T12:58:06","modified_gmt":"2014-03-10T12:58:06","slug":"how-do-i-get-the-datetimestamp-since-last-cron-run-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/10\/how-do-i-get-the-datetimestamp-since-last-cron-run-collection-of-common-programming-errors\/","title":{"rendered":"How do I get the (date)timestamp since last cron run?-Collection of common programming errors"},"content":{"rendered":"<p>hook_requirement() function can help you.<\/p>\n<p>Check this out: http:\/\/api.drupal.org\/api\/drupal\/modules%21system%21system.api.php\/function\/hook_requirements\/7<\/p>\n<p>In your module file write hook_requirement() function.<\/p>\n<pre><code>function hook_requirements($phase) {\nif ($phase == 'runtime') {\n    $cron_last = variable_get('cron_last');\n\n    if (is_numeric($cron_last)) {\n      $requirements['cron']['value'] = $t('Last run !time ago', array('!time' =&gt; format_interval(REQUEST_TIME - $cron_last)));\n    }\n    else {\n      $requirements['cron'] = array(\n        'description' =&gt; $t('Cron has not run. It appears cron jobs have not been setup on your system. Check the help pages for configuring cron jobs.', array('@url' =&gt; 'http:\/\/drupal.org\/cron')), \n        'severity' =&gt; REQUIREMENT_ERROR, \n        'value' =&gt; $t('Never run'),\n      );\n    }\n\n    $requirements['cron']['description'] .= ' ' . $t('You can run cron manually.', array('@cron' =&gt; url('admin\/reports\/status\/run-cron')));\n\n    $requirements['cron']['title'] = $t('Cron maintenance tasks');\n  }\n}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>hook_requirement() function can help you. Check this out: http:\/\/api.drupal.org\/api\/drupal\/modules%21system%21system.api.php\/function\/hook_requirements\/7 In your module file write hook_requirement() function. function hook_requirements($phase) { if ($phase == &#8216;runtime&#8217;) { $cron_last = variable_get(&#8216;cron_last&#8217;); if (is_numeric($cron_last)) { $requirements[&#8216;cron&#8217;][&#8216;value&#8217;] = $t(&#8216;Last run !time ago&#8217;, array(&#8216;!time&#8217; =&gt; format_interval(REQUEST_TIME &#8211; $cron_last))); } else { $requirements[&#8216;cron&#8217;] = array( &#8216;description&#8217; =&gt; $t(&#8216;Cron has not run. It appears [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2926","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2926","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2926"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2926\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2926"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2926"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2926"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}