Empty Date displays default date

21 posts by 5 authors in: Forums > CMS Builder
Last Post: August 24, 2011   (RSS)

By trebien - August 15, 2011

Setting up an "events" page... leaving the date field empty in the editor, but the PHP output shows a date in 1999 instead of nothing. Some event have no date associated with them, so if it's blank, I want the field to remain blank...

Any thoughts?

Re: [trebien] Empty Date displays default date

By Steve99 - August 16, 2011

Hello,
Go to Admin -> Section Editors, and click modify on your "events" editor. Then click modify for your date field. In the Field Options area, change the default value to "None/Blank" and that should do the trick!

Hope this helps.

Re: [steve99] Empty Date displays default date

By trebien - August 17, 2011

That's the thing... that's how we have it set!

We also tried changing that option, saving... then changing it back... but same thing... weird.

Re: [trebien] Empty Date displays default date

By Steve99 - August 17, 2011

Okay. As a fix, you can add a checkbox field to your section editor to toggle "Yes / No" and wrap your date code output in an "IF" statement.

Example:
New Field = display_date (checkbox in your section editor)

Inside your "foreach" loop around your date output:
<?php if ($record['display_date'] == 'Yes'): ?>
<?php echo $record['date'] ?>
<?php endif ?>

Re: [steve99] Empty Date displays default date

By trebien - August 17, 2011

Yeah, it looks like this is what we will have to do... I'm just trying to figure out why the original functionality isn't working.

Re: [trebien] Empty Date displays default date

By robin - August 17, 2011

Hey,

Are you directly outputting the date field? Like
<?php echo $record['date'] ?>
Or are you running it through any functions first?

Thanks,
Robin
Robin
Programmer
interactivetools.com

Re: [robin] Empty Date displays default date

By trebien - August 17, 2011

Just the code generated by the Code Generator:

<?php echo date("D, M jS, Y g:i a", strtotime($record['date'])) ?>

Re: [trebien] Empty Date displays default date

By robin - August 17, 2011

Is the wrong date that it's outputting November 30th, 1999?

Thanks
Robin
Programmer
interactivetools.com

Re: [robin] Empty Date displays default date

By trebien - August 17, 2011

Yeah, some default date.