Weird date displayed in Custom Template for Page List Block

I created a few custom attributes for the page list block to display a date and time range. The code that I used works pretty well except when I leave any of the attributes blank, I get a really weird date and time. The link below is from the archived forms and I’m having this exact issue.

Below is a code snippet from from my template.

<p><?php echo '<span>' . date('D, F j, y', strtotime($eventStartDate)) . '</span>' . ' - '. '<span>' . date('D, F j, y', strtotime($eventEndDate)) . '</span>'?>

Does strtotime() of an empty value lead to 1 Jan 1970?

When an attribute is blank the date is December 16 1960.

That implies a negative return from strtotime() is being formatted into a date.

How do I stop that? Should I use some other function besides strtotime()?

If the input from the attribute is blank, there is no valid date/time. The rest is just computing invalid results from an invalid input.
You either need a default date/time to show, or to show an alternate message, or to show nothing.

Ok. So I can do a PHP if else statement that says if no input is entered add a specific message.

I would do something like:
if(!empty($eventStartDate) && !empty($eventEndDate)){
// your usual code
// message or whatever
Maybe modify that further to handle where you have a start and no end, or an end and no start.

1 Like

Ok. That’s what I was thinking. Thanks John. Your help is always appreciated.