Data hook with dates

I have a collection in Wix that has one column that is formatted as a date (lets call this “post_date”). I have another column that is a boolean variable (call this “post_validate”).

I basically want to set up a data hook that says if the post date has not yet passed, the post validate value is false. That way I only show posts for which the date has passed (I query the database by “post_validate on the respective dynamic page).

Hi,

it is not recommended to indeed save fields which value changes according to time, or any other factor which is not a part of the collection record.
for example prefer holding date of birth rather than age.
if you still need such a calculated field like the above, i highly recommend you calculate it on read.

Shlomi

Hi Shlomi,

Thanks. Would it be easier to write some code in the query on the dynamic page? If so, could you give some guidance as to what this would look like?

Hi,

depends on the context of what you are trying to do, whether this is a repeater, search, dynamic page, table etc.
for example see here on query results you can modify and revise what you read from the db
http://www.wix.com/code/reference/wix-data.html#query

doing it on db hooks will be executed on all pages as it is done in the on db layer.
please have a look at the following for dynamic page:
http://www.wix.com/code/reference/wix-dataset.html#onReady
the event handler on loading the data, and:
http://www.wix.com/code/reference/wix-dataset.html#getCurrentItem
to get the values of your page’s item

shlomi