Problem with strftime

I’m using this code to display the month in a timeline in an abbreviated way. This needs to be translated in two languages.

<?php $somedate = $event->event_datum(); echo date('M Y', strtotime($somedate)) ?>

In another topic, i read i would need strftime for this. When i use this code

<?php $somedate = $event->event_datum(); echo strftime('M Y', $somedate) ?>	

I get the error: strftime() expects parameter 2 to be integer, object given

Could you tell me why i get the error and how i can fix this? Thank you!

First of all, you could set the date handler to strftime in your config:


You can then use the date method

<?php echo $page->date('%b %G', 'event_datum') ?>

Note that the formatting is different for strftime.

The error you get is caused because $page->event_datum() returns a field object, not an integer. You’d have to convert that to a Unix timestamp first using strtotime(). But if you do what I suggested above, you don’t have to do this.

1 Like

Ok, i got it! Thank you.