This question has been answered by jvollands. See the first response.
//[[!getFormatedDateTime]]
//[[!getFormatedDateTime? ×tring=`+1 day`]] see: http://php.net/manual/de/function.strtotime.php
//[[!getFormatedDateTime? ×tring=`+1 day` &format=`%Y-%m-%d`]]
$time = $modx->getOption('time',$scriptProperties,time());
$timestring = $modx->getOption('timestring',$scriptProperties,strftime('%Y-%m-%d %H:%M:%S'));
$format = $modx->getOption('format',$scriptProperties,'%Y-%m-%d %H:%M:%S');
$time = strtotime($timestring,$time);
return strftime($format,$time);
[[!If? &subject=`[[getFormatedDateTime? &time=`[[*publishedon]]`]]` &operand=`[[!getFormatedDateTime? ×tring=`+14 day`]]` &operator=`<` &then=`New` ]]
try this:
new snippet 'getFormatedDateTime'
//[[!getFormatedDateTime]] //[[!getFormatedDateTime? ×tring=`+1 day`]] see: http://php.net/manual/de/function.strtotime.php //[[!getFormatedDateTime? ×tring=`+1 day` &format=`%Y-%m-%d`]] $time = $modx->getOption('time',$scriptProperties,time()); $timestring = $modx->getOption('timestring',$scriptProperties,strftime('%Y-%m-%d %H:%M:%S')); $format = $modx->getOption('format',$scriptProperties,'%Y-%m-%d %H:%M:%S'); $time = strtotime($timestring,$time); return strftime($format,$time);
And with the If - snippet installed, call it like that:
[[!If? &subject=`[[getFormatedDateTime? &time=`[[*publishedon]]`]]` &operand=`[[!getFormatedDateTime? ×tring=`+14 day`]]` &operator=`<` &then=`New` ]]
Personally, I wouldn't use a TV at all. I'd use a snippet, and output "New" as long as the resource's pub_date was less than or equal to two weeks before today.
[[!New]]
<?php
/* New snippet */
/* Get the publishedon date */
$publishedOn = $modx->resource->get('publishedon');
/* This will be returned if it's not published or
more than two weeks old */
$output = '';
/* Do nothing if the resource is not published */
if (!empty($publishedOn)) {
/* It's published -- convert the pub date to a timestamp */
$pTime = strtotime($publishedOn);
/* See if it's less than two weeks old */
if ( ($pTime + 1209600) > time()) {
/* It is. Set the output to 'New' */
$output = 'New';
/* or in case you want to style it -- */
/* $output = '<span style="new_resource">New</span>'; */
}
}
return $output;
I believe pub_date is set to 0 when the Resource is published. I think you want the publishedon field.
Using Susan's suggestion, you'd just create a snippet called New containing the code below and put this tag where you want the word 'New' to appear:
[[!New]]
<!--?php /* New snippet */ /* Get the publishedon date */ $publishedOn = $modx--->resource->get('publishedon'); /* This will be returned if it's not published or more than two weeks old */ $output = ''; /* Do nothing if the resource is not published */ if (!empty($publishedOn)) { /* It's published -- convert the pub date to a timestamp */ $pTime = strtotime($publishedOn); /* See if it's less than two weeks old */ if ( ($pTime + 1209600) > time()) { /* It is. Set the output to 'New' */ $output = 'New'; /* or in case you want to style it -- */ /* $output = '<span style="new_resource">New</span>'; */ } } return $output;
I do like Bruno17's method too, though the timestring property looks funky on my machine -- maybe the forum mangled it. My method might be easier to understand, and I think may involve less computation.
If this works, you can remove the TV.