Note that there are some explanatory texts on larger screens.

plurals
  1. POCakePHP : Search date from form helper
    primarykey
    data
    text
    <p>I use form helpers to show drop down select date. My problem is, i can't compare date from ms sql with form data.</p> <p>My View :</p> <pre><code>&lt;?php echo $this-&gt;Form-&gt;input('collect_date', array('label' =&gt; 'Collect Date','type'=&gt;'date','dateFormat'=&gt; 'DMY','minYear' =&gt; date('Y'),'maxYear' =&gt; date('Y')+1));?&gt; </code></pre> <p>My Controller</p> <pre><code>$status =array(0,2,4); $find_date = $this-&gt;data['Transaction']['collect_date']; $field = array('Transaction.status','Catalogue.title', 'Catalogue.author', 'Catalogue.isbn', 'Location.rack'); $condition = array('OR' =&gt; array('AND' =&gt;array('Transaction.return_date &lt;'=&gt; $find_date,'Transaction.status '=&gt; '3'),array('Transaction.status'=&gt; $status))); $data = $this-&gt;Catalogue-&gt;Transaction-&gt;find('count',array('fields' =&gt; $field,'conditions'=&gt;$condition,'order'=&gt;array('Transaction.id desc') )); $this-&gt;set('Found', $data); </code></pre> <p>And the sql dump</p> <pre><code>SELECT COUNT(*) AS [count] FROM [transactions] AS [Transaction] LEFT JOIN [catalogues] AS [Catalogue] ON ([Transaction].[catalogue_id] = [Catalogue].[id]) LEFT JOIN [users] AS [User] ON ([Transaction].[user_id] = [User].[id]) WHERE (((([Transaction].[return_date] &lt; ('01', '09', 2013)) AND ([Transaction].[status] = 3))) OR ([Transaction].[status] IN (0, 2, 4))) </code></pre> <p>As you can see the date format ('01', '09', 2013). But when try to convert use this</p> <pre><code>'Transaction.return_date &lt;'=&gt; date('Y-m-d', strtotime($find_date)) </code></pre> <p>it show error:</p> <pre><code>Warning (2): strtotime() expects parameter 1 to be string, array given [APP\Controller\CataloguesController.php, line 66] </code></pre> <p>and the sql show:</p> <pre><code>[Transaction].[return_date] &lt; '1970-01-01' </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload