1

I would like to show interval time for nodes were last modified. I am using the following code:

<?php print "Last Modified" . format_interval($node->changed, $langcode, "short"); ?>

I am using $langcode as proposed here to display it in Arabic, but it is not working and I am not sure if I am using it the right way because I get this error Notice: Undefined variable: langcode in include()

Whenever I update any content; interval time still set to 0 sec, so what is wrong with the code?

1 Answer 1

0

Your code contains two errors:

  • You are using a variable which has not been initialized
  • You are passing the wrong arguments to format_interval()

The required arguments are:

  • $interval
    It's not a timestamp, but the number of seconds until now. In your case, you should use time() - $node->changed.

  • $granularity It's the number of units that are shown; if you pass 2 as value for $granularity and the interval is for 1 year, 3 months, and 2 weeks, format_interval() will return "1 year 3 months".

  • $langcode
    It's the language code for the language to use. If you are hard-coding the language to be Arabic, you should use "ar".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.