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)

Re: [equinox69] Date Field Enhancement problem, v2.02, but maybe 2.01 also

Hi,

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
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

HELP NEEDED on this, please: Re: [gkornbluth] Date Field Enhancement problem, v2.02, but maybe 2.01 also

By Codee - January 19, 2010

IT,
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

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.
Dave Edis - Senior Developer
interactivetools.com

Re: [Dave] Date Field Enhancement problem, v2.02, but maybe 2.01 also

By Codee - January 20, 2010

Thanks Dave. I'll test it shortly and report back. I appreciate it.

Re: [Dave] Date Field Enhancement problem, v2.02, but maybe 2.01 also

By Codee - January 20, 2010

Dave,
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

No problem, I think moving forward we'll want this as is so you can use the same value in 'where' queries (which check the database) and php if statements (which check the value CMSB returns).

So just remember that blank dates are displayed as '0000-00-00 00:00:00' or when in doubt, print out the value.
Dave Edis - Senior Developer
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
Rusty