# In a date query, does not return a string within a condition well

**URL:** <https://discourse.cakephp.org/t/in-a-date-query-does-not-return-a-string-within-a-condition-well/5997>\
**Category:** Need Help\
**Created:** [April 26, 2019, 10:08am UTC](https://discourse.cakephp.org/t/in-a-date-query-does-not-return-a-string-within-a-condition-well/5997 "2019-04-26T10:08:28Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bichomen](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bichomen/32/1070_2.png) [@bichomen](https://discourse.cakephp.org/u/bichomen)\
**Post date:** [April 26, 2019, 10:08am UTC](https://discourse.cakephp.org/t/in-a-date-query-does-not-return-a-string-within-a-condition-well/5997/1 "2019-04-26T10:08:28Z")

</div>

Hi, I have a query where I find out if a date in the database is empty or not:  
…  
Marriage\_date’ =\> ‘if(Marriages.date != 0000-00-00, Marriages.date, “no date recorded”)’,  
…

If I execute the query for example in phpmyadmin, it works, if there is no date it returns “no date recorded” but in cakephp, when recovering in the view the marriage\_date field, it returns a numeration that does not make sense, on the other hand if there is date, it returns the correct date. Why not return the string if the date is 0000-00-00?

---

<div class="post-metadata">

**Author:** ![emilushi](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/emilushi/32/1350_2.png) [@emilushi](https://discourse.cakephp.org/u/emilushi)\
**Post date:** [April 26, 2019, 10:46am UTC](https://discourse.cakephp.org/t/in-a-date-query-does-not-return-a-string-within-a-condition-well/5997/2 "2019-04-26T10:46:43Z")

</div>

I think the condition on the code you wrote should be:  
`'Marriage_date' => Marriages.date !== '0000-00-00' ? Marriages.date : 'no date recored'`

---

<div class="post-metadata">

**Author:** ![bichomen](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/bichomen/32/1070_2.png) [@bichomen](https://discourse.cakephp.org/u/bichomen)\
**Post date:** [April 26, 2019, 11:44am UTC](https://discourse.cakephp.org/t/in-a-date-query-does-not-return-a-string-within-a-condition-well/5997/3 "2019-04-26T11:44:19Z")

</div>

> [@bichomen](#):
>
> marriage\_date

Thanks, but the condition is well written and I found the problem to see what I was returning to a JavaScript `alert: '<script language = "javascript"> alert ("<? = Marriage_date;?>"); </ Script> ';` when making an echo directly on the screen, I realized that I returned the string correctly, I do not know why the alert interpreted something else.
