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
Re: [trebien] Empty Date displays default date
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
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
Except for it's outputting November 30th, 1999..
Re: [trebien] Empty Date displays default date
Did the plugin work?
Jerry Kornbluth
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
Re: [trebien] Empty Date displays default date
The apparent problem is not really a problem, but has to do with the way dates are interpreted in PHP. You can read more about PHP and Dates by Googling the subject
The plugin also solves the problem of spaces in otherwise blank fields messing up If statements that test for the existence of data.
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
Re: [trebien] Empty Date displays default date
By Damon - August 18, 2011
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'])); }
?>
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
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
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.
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
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
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php