Can removeDate be optional?

5 posts by 2 authors in: Forums > CMS Builder
Last Post: November 30, 2010   (RSS)

By zip222 - November 29, 2010 - edited: November 30, 2010

I would like to use the removeDate field, but it seems that it's required. If I leave the field blank when adding a record, the record doesn't show up on the site. This means the user needs to specify a removeDate for every item, which isn't practical. Am I overlooking something?

Re: [zip222] Can removeDate be optional?

By Jason - November 30, 2010

Hi,

The removeDate is optional, but by default it will be factored into your query. If a date field is empty, it is stored as a value of 0000-00-00 00:00:00.

If you want to have removeDate as a field but only want it to be factored if removeDate actually has a value, you can structure your query like this:

list($newsRecord, $newsMetaData) = getRecords(array(
'tableName' => 'news',
'where' => "removeDate >= NOW() OR removeDate='0000-00-00 00:00:00'",
'ignoreRemoveDate' => true,
));


ignoreRemoveDate will take away the automatic where clause that removeDate creates. We then create our own where clause that looks for removeDate to be after the current date, or to have no value.

Hope this helps
---------------------------------------------------
Jason Sauchuk - Project Manager
interactivetools.com

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

Re: [Jason] Can removeDate be optional?

By zip222 - November 30, 2010

Great. And how would I combine that with another where statement that I need to include...

'where' => 'archive=0',
'where' => "removeDate >= NOW() OR removeDate='0000-00-00 00:00:00'",

Re: [Jason] Can removeDate be optional?

By zip222 - November 30, 2010

Thanks again. And in case anyone else tries to utilize this, note that you also need to add the "'ignoreRemoveDate' => true," to your detail pages.