# CakePHP 3: How to create Case statements WHEN DATE field IS NULL THEN set NOW()

**URL:** <https://discourse.cakephp.org/t/cakephp-3-how-to-create-case-statements-when-date-field-is-null-then-set-now/849>\
**Category:** Need Help\
**Created:** [July 29, 2016, 8:47pm UTC](https://discourse.cakephp.org/t/cakephp-3-how-to-create-case-statements-when-date-field-is-null-then-set-now/849 "2016-07-29T20:47:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Salines](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/salines/32/3166_2.png) [@Salines](https://discourse.cakephp.org/u/Salines)\
**Post date:** [July 29, 2016, 8:47pm UTC](https://discourse.cakephp.org/t/cakephp-3-how-to-create-case-statements-when-date-field-is-null-then-set-now/849/1 "2016-07-29T20:47:52Z")

</div>

I have several tables in which I need to save time ranges of certain events (education, work, …). But users in html form can indicate that the event is still going on, so DATE field “event\_end” is by default NULL.

When selecting events they have to be sorted by “event\_start” and “event\_end”.

But if the “event\_end” value IS NULL should it prove to be the current date.

How to do it?
