Empty Date displays default date

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

By trebien - August 18, 2011

Ok... I guess what I'm curious about is where it's pulling that date from, and why the system is defaulting that date into the database for blank space in the drop-down selectors in the editor.

Re: [trebien] Empty Date displays default date

Did the plugin work for you?

Here's the blank date explanation from the "Working With Dates" section of my CMSB Cookbook http://www.thecmsbcookbook.com

In V2.01+ if you have a blank date field, the date stored in your database is actually 0000-00-00 00:00:00, which is the default format MySQL stores dates in.

So, if you try to display the date, the technical reason you get 1969 or 1970 is because the way many servers record time is as epoch time or "seconds since midnight 1970 GMT", so what strtotime() does is covert your date to epoch time, but since your date is zeroed out you get 0 seconds since 1970, which the date() function interprets as 1970, and then adjusts for your timezone (GMT -n hours?)

Hope that answers your question,

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By trebien - August 18, 2011

Thanks for the explanation... and we're on 2.09 I believe...

Except for it's outputting November 30th, 1999..

Re: [trebien] Empty Date displays default date

You're welcome.

Did the plugin work?

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php

By trebien - August 18, 2011

We haven't had time to download and try it, yet... and wanted to see if this was an issue that needed to be addressed through 3rd party, or if there truly is an issue with CMSB so that it can be fixed to begin with... since it is part of the native functionality of CMSB out of the box.

Re: [trebien] Empty Date displays default date

By Damon - August 18, 2011

The value in blank date fields is 0000-00-00 00:00:00.

Using a an IF statement, you can only output the date if it is NOT that value.

Try this code:

<?php if($record['date'] != "0000-00-00 00:00:00")
{ echo date("D, M jS, Y g:i:s a", strtotime($record['date'])); }
?>

Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] Empty Date displays default date

By trebien - August 22, 2011 - edited: August 22, 2011

Thanks, Damon... did the trick. Seems like CMSB would have some date validation for blank dates, but I understand the dilemma.

And for others with the same issues, copy the above code for your "events" page, but then don't forget the following code for your "events_detail" page:


<?php if($eventsRecord['date'] != "0000-00-00 00:00:00")
{ echo date("D, M jS, Y g:i:s a", strtotime($eventsRecord['date'])); }
?>

Re: [trebien] Empty Date displays default date

By Damon - August 22, 2011

Glad to hear the code worked for you.

If anyone else is having a similar issue, first echo the date to see what the server is returning:

<?php echo $record['date'] ; ?>

Depending the the server configuration, some servers may return a date in a slighly different format. Once you know the format, you can use that in the IF statement.
Cheers,
Damon Edis - interactivetools.com

Hire me! Save time by getting our experts to help with your project.
http://www.interactivetools.com/consulting/

Re: [Damon] Empty Date displays default date

Hi Damon,

I thought the reason that Dave wrote that plugin was so you didn't have to write that code on each page. It's been working on all my sites.

Jerry Kornbluth
The first CMS Builder reference book is now available on-line!







Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php