Help me clean my code

Permalink
I needed to have certain (news) entries listed in a page list only during a certain period as defined by the editor. I've added two attribute fields, date format, named pub_date and exp_date ("publish on date" and "expiry date"). Also made a custom page-list template, adding the following code:
$pubdate=$cobj->getCollectionAttributeValue('pub_date');
      $expdate=$cobj->getCollectionAttributeValue('exp_date');
      $datetoday=date("Ymd",(strtotime($date->getLocalDateTime('now'))));
      if ($pubdate=='' || $pubdate==NULL) {
         ($pubdate=$datetoday);
          } else {
         $pubdate=date("Ymd",strtotime($cobj->getCollectionAttributeValue('pub_date')));
            }
      if ($expdate=='' || $expdate==NULL) {
         ($expdate=$datetoday);
          } else {   
         $expdate=date("Ymd",strtotime($cobj->getCollectionAttributeValue('exp_date')));
            }
      $title = $textHelper->entities($cobj->getCollectionName());
      if (($expdate>=$datetoday) && ($pubdate<=$datetoday)) {

While this seems to work as intended I'm slightly annoyed by having to introduce "strtotime" in order to make the selection work. I have a feeling it could be made to work in a slightly more "stream lined" manner, but I'm a novice with PHP. Any suggestions for improvements?

Thanks in advance for any assistance
Søren, Denmark

 
pvernaglia replied on at Permalink Best Answer Reply
pvernaglia
Concrete has a date helper you can use instead of strtotime

$date = Loader::helper("date");
  if($date->getSystemDateTime($c->getCollectionAttributeValue('end_date_attribute'), $mask = 'd-m-Y G:i') > $date->getLocalDateTime('now',$mask = 'd-m-Y G:i')) {
    echo 'End date is greater than today';
  }


http://www.weblicating.com/c5/cheat-sheet/...
sokristi replied on at Permalink Reply
Uses the API, so probably the way to go. Thanks a bunch!