Custom date format (php callback)

I want to create a dynamic php date format. Example: show the time node if it was published today, and only the day / month when it is older than today. I want this format to be available throughout Drupal, as well as other predefined date formats in Drupal (not just at the theme level) .

I found a hook (only for D7) for hook_date_format_types, but even that doesn't seem to allow a callback where I could define this PHP logic.

Does anyone know which hook will make this possible? Or a module that does this?

+5
source share
4 answers

Drupal6 format_date() , . , format_date() , . : , , , .

function mydate_format($timestamp) {
  $now = time();
  if (($now - $timestamp) < (60*60*24)) {
    return "H:i";
  }
  else {
    return "d:m:Y";
  }
}

print format_date($timestamp, 'custom', mydate_format($timestamp));

, - , , . _get(), ; , , .

settings.php:

$conf['date_format_long'] = $conf['debug'] ? 'r' : 'l, F j, Y - H:i';

, , settings.php "debug", TRUE . : , - .

- Date API, onlinle. ( PHP ). . , : format_date, format_date(). . Drupal.org.

GOTCHA Drupal . , , alltogether, javascript .

TL; DR. . "" - , .

+1

API , . API Date. API Date "admin/settings/date-time/formats/add" , .

"admin/settings/date-time/formats/configure" - .

. .

RT

0

node.tpl.php(, /all/themes/theme _name/node.tpl.php). yo $created, , . .

Regatds, Chintan.

0

. .

In the resulting function module in the [feature] .module file, create the hook_nodeapi function and format the conditional expression field, which takes into account the current date () for how the date will be displayed and serve it in $ node → content var.

And so will rock stars (-;

0
source

All Articles