When did Kirby change date comparisons?

Until 2.5.3 (I think) it was possible to compare dates in Kirby using a format like:

<?php if ($page->date('M-d-y') >= date('M-d-y'): ?>
Do something
<?endif ?>

Which was nice since Kirby seemed to be doing the required strtotime comversion. This is no longer the case with version 2.5.5. It this a bug or an intended output of the new version?

I can’t reproduce this, works in a starterkit. Have you changed the date handler maybe?

Thanks for getting back to me so quickly.

I have not changed the date handler and I can reproduce this in the latest starterkit. The test code is below.
I have included both versions of the php output. They should be identical but they are not when setting a date greater than the today date.

content1:
label: TEST
type: structure
modalsize: large
style: table
fields:
  date:
    label: Test Date
    type: date
    format: MM/DD/YYYY
   registration:
    label: Registration
    type: text

 <?php foreach($page->content1()->toStructure()->sortBy('date','desc') as $test): ?>
<?php if ($test->date('M-d-y') >= date('M-d-y')):?> 
  REGISTER
<?php else: ?>
    CLOSED
<?php endif ?>
<?php 
$date1 =strtotime($test->date('M-d-y'));
$date2 =strtotime(date('M-d-y'));
?>
<?php if ($date1 >= $date2 ):?> 
  REGISTER1
<?php else: ?>
    CLOSED1
<?php endif ?>
<?php endforeach ?>

I don’t quite understand why you need a format to compare timestamps. $test->date() returns a UNIX timestamp which you can compare against the current timestamp returned from the time() function:

<?php foreach($page->content1()->toStructure()->sortBy('date','desc') as $test): ?>
    <?php if ($test->date() >= time()): ?>
      REGISTER  <hr>
    <?php else: ?>
        CLOSED <hr>
    <?php endif ?>
    <?php endforeach ?>

1 Like