Date Field Enhancement problem, v2.02, but maybe 2.01 also
8 posts by 4 authors in: Forums > CMS Builder
Last Post: December 21, 2010 (RSS)
By Codee - January 18, 2010 - edited: December 30, 2010
I set up some date/time fields as "default value None/Blank" and checked only "user specifies time (hour, minutes, and optionally seconds)". The available date years are 2010 through 2020.
Then I entered a record and chose the "blank spot" in the date fields at the top of the selection list.
My viewer code is like this:
<?php if ($eventRecord['start_date']): ?>
<b/>Event Start Date: <?php echo date("D, M jS, Y g:i:s a", strtotime($eventRecord['start_date'])) ?></b/><br/><br/>
<?php endif ?>
What's happening is on the public view page, where a blank should exist (or no record), the following date appears as a default
Wed, Dec 31st, 1969 4:00:00 pm
I can temporarily work around this by adding a checkbox to display date or not...but that shouldn't need to occur.
Please help.
Re: [equinox69] Date Field Enhancement problem, v2.02, but maybe 2.01 also
The issue exists in 2.01 because I was just going to post the same question.
I'm sure the masterminds will have an elegant solution.
(hope it's not something we're both overlooking)
Best,
Jerry Kornbluth
Take advantage of a free 3 month trial subscription, only for CMSB users, at: http://www.thecmsbcookbook.com/trial.php
HELP NEEDED on this, please: Re: [gkornbluth] Date Field Enhancement problem, v2.02, but maybe 2.01 also
By Codee - January 19, 2010
PLEASE take note and respond to this issue. I have 2 clients with v2.01 CMSB that this is affecting. My workaround is too clunky of a solution because it's a problem with the system and not a wish-list function.
thanks.
Re: [equinox69] Date Field Enhancement problem, v2.02, but maybe 2.01 also
By Dave - January 19, 2010
Can you try printing out your date value like this to check it's value?
'<?php echo $eventRecord['start_date'] ?>'
My guess is your date is 0000-00-00 00:00:00, which is the default format MySQL stores dates in if there is no date.
If that's the case, you can test for this by adding this code:
<?php if ($eventRecord['start_date'] && $eventRecord['start_date'] != '0000-00-00 00:00:00'): ?>
Incidentally, this is a good check to do anytime your "if" isn't working as you expect, just print out the values (and put quotes around them so you can see extra spaces if any, a common gotcha with non-date values: not matching an if because of an extra space).
The technical reason you get 1969 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 zero'd out you get 0 seconds since 1970, which the date() function interprets as 1970, and then adjusts for your timezone (GMT -8 hours?)
I could look into blanking out the date if there's no date specified. It's not really how it looks in the database but it would probably make more sense in the viewer code. I'll have to make sure there's no other technical implications of that. If anyone has a preference let me know. The above code will work with either value (blank or zero'd out).
Hope that helps! Let me know if you have any other questions or problems with this issue.
interactivetools.com
Re: [Dave] Date Field Enhancement problem, v2.02, but maybe 2.01 also
By Codee - January 20, 2010
Re: [Dave] Date Field Enhancement problem, v2.02, but maybe 2.01 also
By Codee - January 20, 2010
the added test clause works perfectly. Thanks for deducing the issue and providing a ready fix so I could take care of the clients immediately.
Please let me know if/when a plugin or release change occurs that addresses this.
Thank you SO much!
Re: [equinox69] Date Field Enhancement problem, v2.02, but maybe 2.01 also
By Dave - January 20, 2010
So just remember that blank dates are displayed as '0000-00-00 00:00:00' or when in doubt, print out the value.
interactivetools.com
Re: [Dave] Date Field Enhancement problem, v2.02, but maybe 2.01 also
By Rusty - December 21, 2010
Hi Terry,
Can you try printing out your date value like this to check it's value?
'<?php echo $eventRecord['start_date'] ?>'
My guess is your date is 0000-00-00 00:00:00, which is the default format MySQL stores dates in if there is no date.
If that's the case, you can test for this by adding this code:
<?php if ($eventRecord['start_date'] && $eventRecord['start_date'] != '0000-00-00 00:00:00'): ?>
Incidentally, this is a good check to do anytime your "if" isn't working as you expect, just print out the values (and put quotes around them so you can see extra spaces if any, a common gotcha with non-date values: not matching an if because of an extra space).
The technical reason you get 1969 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 zero'd out you get 0 seconds since 1970, which the date() function interprets as 1970, and then adjusts for your timezone (GMT -8 hours?)
I could look into blanking out the date if there's no date specified. It's not really how it looks in the database but it would probably make more sense in the viewer code. I'll have to make sure there's no other technical implications of that. If anyone has a preference let me know. The above code will work with either value (blank or zero'd out).
Hope that helps! Let me know if you have any other questions or problems with this issue.
Thank you Dave, I had almost given up on searching and was this close to posting how I could get the date to hide if it was left "blank/000's"
So now we know how to filter or hide or screen or keep blank dates from showing or displaying if they are 0000-00-00 00:00:00, "D, M jS, Y g:i:s a", strtotime
I'm done keywording :D