Easy Date/Time Snippet for MODX Revolution

Please note: I have shifted my focus to Python/ Linux/ embedded development and am no longer accepting MODX or PHP projects. For MODX work, I recommend Grey Sky Media.

Usage: [[!now? &format=`%Y` ]]

Parameters:
  • format: the format passed to strftime. If left empty, generates a timestamp.
  • type: A date/time input string that sets which date/time to use. Defaults to 'now'. Can be any string accepted by strtotime.
Snippet code:
$type = $modx->getOption('type',$scriptProperties,'now');
$date = $output = strtotime($type);
$format = $modx->getOption('format',$scriptProperties,'');
if ($format) {
    $output = strftime($format,$date);
}
return $output;